-
Notifications
You must be signed in to change notification settings - Fork 112
feat(ambient-ui): Resources/Config tabs, session table enhancements, navigation overhaul #1638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
20d9850
15510e6
15ffd47
9ea7909
8e07180
471a1e2
46ac03e
fc8efa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| import type { Session, Project } from 'ambient-sdk' | ||
| import type { DomainSession, DomainProject, DomainSessionMessage, SessionPhase, SessionEventType } from '@/domain/types' | ||
| import type { | ||
| DomainSession, DomainProject, DomainSessionMessage, SessionPhase, SessionEventType, | ||
| DomainRepo, DomainReconciledRepo, DomainCondition, ReconciledRepoStatus, ConditionStatus, | ||
| } from '@/domain/types' | ||
|
|
||
| const VALID_PHASES: ReadonlySet<string> = new Set<string>([ | ||
| 'Pending', | ||
|
|
@@ -37,10 +40,85 @@ function parseAnnotations(raw: string): Record<string, string> { | |
| } | ||
| } | ||
|
|
||
| function parseJsonArray(raw: string): unknown[] { | ||
| if (!raw) return [] | ||
| try { | ||
| const parsed: unknown = JSON.parse(raw) | ||
| return Array.isArray(parsed) ? parsed : [] | ||
| } catch { | ||
| return [] | ||
| } | ||
| } | ||
|
|
||
| function parseJsonObject(raw: string): Record<string, string> { | ||
| if (!raw) return {} | ||
| try { | ||
| const parsed: unknown = JSON.parse(raw) | ||
| if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) { | ||
| const result: Record<string, string> = {} | ||
| for (const [key, value] of Object.entries(parsed as Record<string, unknown>)) { | ||
| result[key] = String(value) | ||
| } | ||
| return result | ||
| } | ||
| return {} | ||
| } catch { | ||
| return {} | ||
| } | ||
| } | ||
|
|
||
| const VALID_REPO_STATUSES: ReadonlySet<string> = new Set(['Cloning', 'Ready', 'Failed']) | ||
| const VALID_CONDITION_STATUSES: ReadonlySet<string> = new Set(['True', 'False', 'Unknown']) | ||
|
|
||
| function parseRepos(raw: string): DomainRepo[] { | ||
| return parseJsonArray(raw).map((item) => { | ||
| const r = item as Record<string, unknown> | ||
| return { | ||
| url: String(r.url ?? ''), | ||
| branch: r.branch ? String(r.branch) : null, | ||
| name: r.name ? String(r.name) : null, | ||
| autoPush: Boolean(r.autoPush), | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| function parseReconciledRepos(raw: string): DomainReconciledRepo[] { | ||
| return parseJsonArray(raw).map((item) => { | ||
| const r = item as Record<string, unknown> | ||
| const status = String(r.status ?? '') | ||
| return { | ||
| url: String(r.url ?? ''), | ||
| name: r.name ? String(r.name) : null, | ||
| status: VALID_REPO_STATUSES.has(status) ? (status as ReconciledRepoStatus) : null, | ||
| currentActiveBranch: r.currentActiveBranch ? String(r.currentActiveBranch) : null, | ||
| defaultBranch: r.defaultBranch ? String(r.defaultBranch) : null, | ||
| clonedAt: r.clonedAt ? String(r.clonedAt) : null, | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| function parseConditions(raw: string): DomainCondition[] { | ||
| return parseJsonArray(raw).map((item) => { | ||
| const c = item as Record<string, unknown> | ||
| const status = String(c.status ?? 'Unknown') | ||
| return { | ||
| type: String(c.type ?? ''), | ||
| status: VALID_CONDITION_STATUSES.has(status) ? (status as ConditionStatus) : 'Unknown', | ||
| reason: c.reason ? String(c.reason) : null, | ||
| message: c.message ? String(c.message) : null, | ||
| lastTransitionTime: c.lastTransitionTime ? String(c.lastTransitionTime) : null, | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| function emptyToNull(value: string): string | null { | ||
| return value || null | ||
| } | ||
|
|
||
| function numberOrNull(value: number): number | null { | ||
| return value === 0 || value === undefined || value === null ? null : value | ||
| } | ||
|
Comment on lines
+118
to
+120
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also applies to: 132-132 🤖 Prompt for AI Agents |
||
|
|
||
| export function mapSdkSessionToDomain(sdk: Session): DomainSession { | ||
| const annotations = parseAnnotations(sdk.annotations) | ||
| return { | ||
|
|
@@ -51,11 +129,22 @@ export function mapSdkSessionToDomain(sdk: Session): DomainSession { | |
| agentName: annotations['agent_name'] ?? null, | ||
| projectId: emptyToNull(sdk.project_id), | ||
| model: emptyToNull(sdk.llm_model), | ||
| temperature: numberOrNull(sdk.llm_temperature), | ||
| maxTokens: numberOrNull(sdk.llm_max_tokens), | ||
| timeout: numberOrNull(sdk.timeout), | ||
| workflowId: emptyToNull(sdk.workflow_id), | ||
| prompt: emptyToNull(sdk.prompt), | ||
| sdkRestartCount: sdk.sdk_restart_count ?? 0, | ||
| startTime: emptyToNull(sdk.start_time), | ||
| completionTime: emptyToNull(sdk.completion_time), | ||
| createdAt: sdk.created_at ?? '', | ||
| updatedAt: sdk.updated_at ?? '', | ||
| annotations, | ||
| labels: parseJsonObject(sdk.labels), | ||
| environmentVariables: parseJsonObject(sdk.environment_variables), | ||
| repos: parseRepos(sdk.repos), | ||
| reconciledRepos: parseReconciledRepos(sdk.reconciled_repos), | ||
| conditions: parseConditions(sdk.conditions), | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard against non-object array entries before property access.
parseJsonArraycan legitimately return arrays containingnullor primitives (e.g. backend emits"[null]"or"[1,2]"). Hereconst r = item as Record<string, unknown>is a compile-time-only cast; at runtimer.urlon anullitem throwsTypeError, and the.mapisn't wrapped in try/catch — so a malformedrepos/reconciled_repos/conditionspayload crashes the render of the Resources/Config tabs.🛡️ Suggested guard (apply to all three parsers)
🤖 Prompt for AI Agents