@agent-native/core 0.12.9 → 0.12.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/engine/builder-engine.d.ts.map +1 -1
- package/dist/agent/engine/builder-engine.js +10 -2
- package/dist/agent/engine/builder-engine.js.map +1 -1
- package/dist/agent/engine/translate-ai-sdk.d.ts +2 -2
- package/dist/agent/engine/translate-ai-sdk.d.ts.map +1 -1
- package/dist/agent/engine/translate-ai-sdk.js +19 -2
- package/dist/agent/engine/translate-ai-sdk.js.map +1 -1
- package/dist/agent/engine/types.d.ts +9 -0
- package/dist/agent/engine/types.d.ts.map +1 -1
- package/dist/agent/engine/types.js.map +1 -1
- package/dist/agent/production-agent.d.ts +2 -1
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +202 -4
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/types.d.ts +32 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/cli/workspace-dev.js +17 -0
- package/dist/cli/workspace-dev.js.map +1 -1
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +74 -5
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/NewWorkspaceAppFlow.d.ts.map +1 -1
- package/dist/client/NewWorkspaceAppFlow.js +1 -0
- package/dist/client/NewWorkspaceAppFlow.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +147 -7
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
- package/dist/client/composer/TiptapComposer.js +3 -2
- package/dist/client/composer/TiptapComposer.js.map +1 -1
- package/dist/client/composer/pasted-text.d.ts.map +1 -1
- package/dist/client/composer/pasted-text.js +5 -6
- package/dist/client/composer/pasted-text.js.map +1 -1
- package/dist/client/extensions/ExtensionsSidebarSection.js +4 -4
- package/dist/client/extensions/ExtensionsSidebarSection.js.map +1 -1
- package/dist/client/frame.d.ts +8 -0
- package/dist/client/frame.d.ts.map +1 -1
- package/dist/client/frame.js +34 -0
- package/dist/client/frame.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/sharing/ShareButton.d.ts.map +1 -1
- package/dist/client/sharing/ShareButton.js +5 -3
- package/dist/client/sharing/ShareButton.js.map +1 -1
- package/dist/client/sharing/ShareDialog.js +2 -1
- package/dist/client/sharing/ShareDialog.js.map +1 -1
- package/dist/client/sse-event-processor.d.ts +1 -0
- package/dist/client/sse-event-processor.d.ts.map +1 -1
- package/dist/client/sse-event-processor.js +15 -37
- package/dist/client/sse-event-processor.js.map +1 -1
- package/dist/deploy/workspace-deploy.js +4 -0
- package/dist/deploy/workspace-deploy.js.map +1 -1
- package/dist/extensions/routes.d.ts.map +1 -1
- package/dist/extensions/routes.js +10 -1
- package/dist/extensions/routes.js.map +1 -1
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +51 -0
- package/dist/server/auth.js.map +1 -1
- package/dist/server/google-oauth.d.ts.map +1 -1
- package/dist/server/google-oauth.js +19 -1
- package/dist/server/google-oauth.js.map +1 -1
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +1 -0
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/oauth-state.d.ts +10 -0
- package/dist/shared/oauth-state.d.ts.map +1 -0
- package/dist/shared/oauth-state.js +32 -0
- package/dist/shared/oauth-state.js.map +1 -0
- package/dist/templates/default/app/entry.client.tsx +12 -0
- package/dist/templates/default/app/root.tsx +4 -1
- package/dist/templates/workspace-core/AGENTS.md +11 -0
- package/dist/templates/workspace-root/AGENTS.md +11 -0
- package/dist/templates/workspace-root/README.md +7 -1
- package/package.json +1 -1
- package/src/templates/default/app/entry.client.tsx +12 -0
- package/src/templates/default/app/root.tsx +4 -1
- package/src/templates/workspace-core/AGENTS.md +11 -0
- package/src/templates/workspace-root/AGENTS.md +11 -0
- package/src/templates/workspace-root/README.md +7 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NewWorkspaceAppFlow.d.ts","sourceRoot":"","sources":["../../src/client/NewWorkspaceAppFlow.tsx"],"names":[],"mappings":"AAcA,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;
|
|
1
|
+
{"version":3,"file":"NewWorkspaceAppFlow.d.ts","sourceRoot":"","sources":["../../src/client/NewWorkspaceAppFlow.tsx"],"names":[],"mappings":"AAcA,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AA+ED,wBAAgB,mBAAmB,CAAC,EAClC,SAAqB,EACrB,SAAc,EACd,gBAAgB,GACjB,EAAE,wBAAwB,2CA4N1B"}
|
|
@@ -60,6 +60,7 @@ function buildNewWorkspaceAppPrompt(input) {
|
|
|
60
60
|
``,
|
|
61
61
|
`Pick a starter template that fits the user's prompt — analytics, calendar, content, design, dispatch, forms, mail, slides, clips, or starter when none of the others fit.`,
|
|
62
62
|
`Use the workspace app layout: create it under apps/${input.appId}, mount it at /${input.appId}, keep it on the shared workspace database/hosting model, and avoid table-name collisions by namespacing any new domain tables to the app.`,
|
|
63
|
+
`If the user's prompt mentions sibling apps like Mail, Calendar, Dispatch, or other templates, treat them as existing workspace neighbors or integrations. Do not scaffold those sibling apps inside apps/${input.appId} unless the user explicitly asks to create them too.`,
|
|
63
64
|
`Do not satisfy this by adding a route, page, component, or file inside apps/starter or another existing app unless the user explicitly asks to modify that existing app.`,
|
|
64
65
|
keyList
|
|
65
66
|
? `After the app exists, grant the selected Dispatch vault keys to appId "${input.appId}" and sync them once the app server is available. Treat these as requested grants, not active grants before creation succeeds.`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NewWorkspaceAppFlow.js","sourceRoot":"","sources":["../../src/client/NewWorkspaceAppFlow.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,eAAe,EACf,OAAO,GACR,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,gCAAgC,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAgB9D,SAAS,OAAO,CAAC,KAAa;IAC5B,OAAO,KAAK;SACT,WAAW,EAAE;SACb,O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useState } from \"react\";\nimport {\n IconArrowUpRight,\n IconCheck,\n IconChevronDown,\n IconKey,\n} from \"@tabler/icons-react\";\nimport { agentNativePath, appBasePath } from \"./api-path.js\";\nimport { sendToAgentChat } from \"./agent-chat.js\";\nimport { isInBuilderFrame } from \"./builder-frame.js\";\nimport { useDevMode } from \"./use-dev-mode.js\";\nimport { getWorkspaceAppIdValidationError } from \"../shared/workspace-app-id.js\";\nimport { PromptComposer } from \"./composer/PromptComposer.js\";\n\nexport interface VaultSecretOption {\n id: string;\n name: string;\n credentialKey: string;\n provider?: string | null;\n description?: string | null;\n}\n\nexport interface NewWorkspaceAppFlowProps {\n sourceApp?: string;\n className?: string;\n dispatchBasePath?: string | null;\n}\n\nfunction slugify(value: string): string {\n return value\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .replace(/^[^a-z]+/, \"\")\n .slice(0, 48);\n}\n\nfunction titleFromPrompt(prompt: string): string {\n const cleaned = prompt\n .replace(/\\b(build|create|make|an?|the|app|tool|dashboard)\\b/gi, \" \")\n .replace(/\\s+/g, \" \")\n .trim();\n return slugify(cleaned || \"new-app\") || \"new-app\";\n}\n\nfunction actionUrl(basePath: string | null, action: string): string {\n const path = `/_agent-native/actions/${action}`;\n if (basePath === null) return agentNativePath(path);\n const normalized = basePath.replace(/\\/+$/, \"\");\n return `${normalized}${path}`;\n}\n\nfunction defaultDispatchBasePath(sourceApp?: string): string | null {\n if (sourceApp === \"dispatch\") return null;\n const base = appBasePath();\n if (base === \"/dispatch\") return null;\n return \"/dispatch\";\n}\n\nasync function fetchJson(url: string, init?: RequestInit): Promise<any> {\n const res = await fetch(url, init);\n const data = await res.json().catch(() => null);\n if (!res.ok) {\n throw new Error(\n data?.error || data?.message || `Request failed ${res.status}`,\n );\n }\n return data;\n}\n\nfunction buildNewWorkspaceAppPrompt(input: {\n appId: string;\n prompt: string;\n selectedKeys: string[];\n}): string {\n const keyList = input.selectedKeys.join(\", \");\n const grantRequest = keyList\n ? `Requested Dispatch vault key grants for this app: ${keyList}`\n : `Requested Dispatch vault key grants for this app: none`;\n\n return [\n `Create a new agent-native app in this workspace.`,\n `This is a new workspace app request, not a feature request for the current app.`,\n ``,\n `Suggested app name: ${input.appId} (you may adjust the slug if it conflicts)`,\n `User prompt: ${input.prompt.trim()}`,\n grantRequest,\n ``,\n `Pick a starter template that fits the user's prompt — analytics, calendar, content, design, dispatch, forms, mail, slides, clips, or starter when none of the others fit.`,\n `Use the workspace app layout: create it under apps/${input.appId}, mount it at /${input.appId}, keep it on the shared workspace database/hosting model, and avoid table-name collisions by namespacing any new domain tables to the app.`,\n `Do not satisfy this by adding a route, page, component, or file inside apps/starter or another existing app unless the user explicitly asks to modify that existing app.`,\n keyList\n ? `After the app exists, grant the selected Dispatch vault keys to appId \"${input.appId}\" and sync them once the app server is available. Treat these as requested grants, not active grants before creation succeeds.`\n : `Do not grant any Dispatch vault keys unless the user asks later.`,\n ``,\n `App readiness requirements before handing off:`,\n `- Update the workspace app registry metadata for \"${input.appId}\" (workspace-apps.json or .agent-native/workspace-apps.json, whichever this workspace uses) so Dispatch lists the app at /${input.appId} after merge/deploy.`,\n `- Update the app manifest/package/deploy metadata needed by the existing workspace deployment model; do not leave the app relying only on local discovery.`,\n `- Verify the app's agent card/A2A metadata is ready so Dispatch can discover and delegate to the app after deployment.`,\n `- Include a final verification note covering the registry entry, manifest/deploy metadata, and agent-card readiness.`,\n `When it is ready, start or update the workspace dev server and navigate the user to /${input.appId}.`,\n ].join(\"\\n\");\n}\n\nexport function NewWorkspaceAppFlow({\n sourceApp = \"starter\",\n className = \"\",\n dispatchBasePath,\n}: NewWorkspaceAppFlowProps) {\n const [selectedSecretIds, setSelectedSecretIds] = useState<string[]>([]);\n const [secrets, setSecrets] = useState<VaultSecretOption[]>([]);\n const [secretsError, setSecretsError] = useState<string | null>(null);\n const [statusMessage, setStatusMessage] = useState<string | null>(null);\n const [branchUrl, setBranchUrl] = useState<string | null>(null);\n const [isSubmitting, setIsSubmitting] = useState(false);\n const { isDevMode } = useDevMode();\n\n const effectiveDispatchBasePath =\n dispatchBasePath === undefined\n ? defaultDispatchBasePath(sourceApp)\n : dispatchBasePath;\n\n useEffect(() => {\n let cancelled = false;\n const url = actionUrl(\n effectiveDispatchBasePath,\n \"list-vault-secret-options\",\n );\n fetchJson(url)\n .then((data) => {\n if (cancelled) return;\n setSecrets(Array.isArray(data) ? data : []);\n setSecretsError(null);\n })\n .catch((err) => {\n if (cancelled) return;\n setSecrets([]);\n setSecretsError(err?.message || \"Could not load Dispatch keys\");\n });\n return () => {\n cancelled = true;\n };\n }, [effectiveDispatchBasePath]);\n\n const selectedSecrets = useMemo(\n () => secrets.filter((secret) => selectedSecretIds.includes(secret.id)),\n [secrets, selectedSecretIds],\n );\n const selectedSecretLabel =\n selectedSecretIds.length === 0\n ? \"No keys selected\"\n : `${selectedSecretIds.length} key${selectedSecretIds.length === 1 ? \"\" : \"s\"} selected`;\n\n async function submit(rawPrompt: string) {\n const prompt = rawPrompt.trim();\n if (!prompt || isSubmitting) return;\n const appId = titleFromPrompt(prompt);\n const validationError = getWorkspaceAppIdValidationError(appId);\n if (validationError) {\n setStatusMessage(validationError);\n return;\n }\n\n const message = buildNewWorkspaceAppPrompt({\n appId,\n prompt,\n selectedKeys: selectedSecrets.map((s) => s.credentialKey),\n });\n setIsSubmitting(true);\n setStatusMessage(null);\n setBranchUrl(null);\n\n try {\n if (isInBuilderFrame()) {\n sendToAgentChat({ message, submit: true, type: \"code\" });\n setStatusMessage(\"Sent to Builder chat.\");\n } else if (isDevMode) {\n sendToAgentChat({ message, submit: true, type: \"code\", newTab: true });\n setStatusMessage(\"Sent to the local agent.\");\n } else {\n const result = await fetchJson(\n actionUrl(effectiveDispatchBasePath, \"start-workspace-app-creation\"),\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n prompt,\n appId,\n secretIds: selectedSecretIds,\n }),\n },\n );\n if (result?.mode === \"builder\") {\n setBranchUrl(result?.url || null);\n setStatusMessage(\"Builder branch created.\");\n } else {\n setStatusMessage(\n result?.message ||\n \"Builder app creation is coming soon here. Open this workspace in Builder to create an app from this prompt.\",\n );\n }\n }\n } catch (err: any) {\n setStatusMessage(err?.message || \"Could not start the new app flow.\");\n } finally {\n setIsSubmitting(false);\n }\n }\n\n function toggleSecret(id: string) {\n setSelectedSecretIds((current) =>\n current.includes(id)\n ? current.filter((existing) => existing !== id)\n : [...current, id],\n );\n }\n\n return (\n <section\n className={`mx-auto flex w-full max-w-5xl flex-col gap-5 px-4 py-6 ${className}`}\n >\n <div className=\"grid gap-5 lg:grid-cols-[minmax(0,1fr)_320px]\">\n <div className=\"flex flex-col gap-3\">\n <PromptComposer\n autoFocus\n disabled={isSubmitting}\n placeholder=\"Describe the app your teammate should be able to use...\"\n draftScope=\"dispatch:new-app\"\n onSubmit={(text) => submit(text)}\n />\n\n {statusMessage ? (\n <div className=\"rounded-md border border-border bg-muted/40 px-3 py-2 text-sm text-muted-foreground\">\n {statusMessage}\n {branchUrl ? (\n <a\n href={branchUrl}\n target=\"_blank\"\n rel=\"noreferrer\"\n className=\"ml-2 inline-flex items-center gap-1 font-medium text-foreground underline\"\n >\n Open branch <IconArrowUpRight className=\"h-3 w-3\" />\n </a>\n ) : null}\n </div>\n ) : null}\n </div>\n\n <aside className=\"rounded-lg border border-border bg-card\">\n <div className=\"border-b border-border px-4 py-3\">\n <div className=\"flex items-center justify-between gap-3\">\n <div className=\"flex items-center gap-2 text-sm font-medium\">\n <IconKey className=\"h-4 w-4\" />\n Dispatch keys\n </div>\n <span className=\"shrink-0 rounded border border-border bg-background/40 px-2 py-0.5 text-[11px] text-muted-foreground\">\n {selectedSecretLabel}\n </span>\n </div>\n </div>\n <div className=\"max-h-[440px] space-y-2 overflow-y-auto p-3\">\n {secretsError ? (\n <p className=\"rounded-md border border-dashed border-border px-3 py-3 text-xs text-muted-foreground\">\n {secretsError}\n </p>\n ) : secrets.length === 0 ? (\n <p className=\"rounded-md border border-dashed border-border px-3 py-3 text-xs text-muted-foreground\">\n No Dispatch vault keys found yet.\n </p>\n ) : (\n secrets.map((secret) => {\n const selected = selectedSecretIds.includes(secret.id);\n return (\n <div\n key={secret.id}\n className={`group rounded-md border text-sm transition ${\n selected\n ? \"border-primary/45 bg-primary/5 text-foreground shadow-[inset_0_0_0_1px_hsl(var(--primary)/0.08)]\"\n : \"border-border bg-background/25 text-foreground hover:border-muted-foreground/40 hover:bg-accent/35\"\n }`}\n >\n <button\n type=\"button\"\n aria-pressed={selected}\n onClick={() => toggleSecret(secret.id)}\n className=\"flex w-full cursor-pointer items-start gap-3 rounded-md px-3 py-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/30\"\n >\n <span\n className={`mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded border transition ${\n selected\n ? \"border-primary/60 bg-primary/10 text-primary\"\n : \"border-muted-foreground/35 text-transparent group-hover:border-muted-foreground/60\"\n }`}\n >\n {selected ? <IconCheck className=\"h-3 w-3\" /> : null}\n </span>\n <span className=\"min-w-0 flex-1\">\n <span className=\"block truncate font-medium\">\n {secret.credentialKey}\n </span>\n <span className=\"block truncate text-xs text-muted-foreground/70\">\n {selected\n ? \"Will be requested for this app\"\n : \"Click to request\"}\n </span>\n </span>\n </button>\n <details className=\"group/details border-t border-border/60 px-3 py-1.5 text-xs text-muted-foreground/75 open:bg-background/10\">\n <summary className=\"flex cursor-pointer list-none items-center gap-1.5 text-[11px] hover:text-muted-foreground [&::-webkit-details-marker]:hidden\">\n <IconChevronDown className=\"h-3 w-3 transition-transform group-open/details:rotate-180\" />\n Details\n </summary>\n <div className=\"mt-1.5 space-y-1 pb-0.5 pl-4\">\n <div className=\"truncate\">\n Provider: {secret.provider || \"Not specified\"}\n </div>\n <div className=\"truncate\">Name: {secret.name}</div>\n </div>\n </details>\n </div>\n );\n })\n )}\n </div>\n </aside>\n </div>\n </section>\n );\n}\n"]}
|
|
1
|
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GAAG,CAAC,CAAC,CAAC,IAAI,GAC/C,EACP,gBAAM,SAAS,EAAC,gBAAgB,aAC9B,eAAM,SAAS,EAAC,4BAA4B,YACzC,MAAM,CAAC,aAAa,GAChB,EACP,eAAM,SAAS,EAAC,iDAAiD,YAC9D,QAAQ;gEACP,CAAC,CAAC,gCAAgC;gEAClC,CAAC,CAAC,kBAAkB,GACjB,IACF,IACA,EACT,mBAAS,SAAS,EAAC,4GAA4G,aAC7H,mBAAS,SAAS,EAAC,+HAA+H,aAChJ,KAAC,eAAe,IAAC,SAAS,EAAC,4DAA4D,GAAG,eAElF,EACV,eAAK,SAAS,EAAC,8BAA8B,aAC3C,eAAK,SAAS,EAAC,UAAU,2BACZ,MAAM,CAAC,QAAQ,IAAI,eAAe,IACzC,EACN,eAAK,SAAS,EAAC,UAAU,uBAAQ,MAAM,CAAC,IAAI,IAAO,IAC/C,IACE,KA5CL,MAAM,CAAC,EAAE,CA6CV,CACP,CAAC;4BACJ,CAAC,CAAC,CACH,GACG,IACA,IACJ,GACE,CACX,CAAC;AACJ,CAAC","sourcesContent":["import { useEffect, useMemo, useState } from \"react\";\nimport {\n IconArrowUpRight,\n IconCheck,\n IconChevronDown,\n IconKey,\n} from \"@tabler/icons-react\";\nimport { agentNativePath, appBasePath } from \"./api-path.js\";\nimport { sendToAgentChat } from \"./agent-chat.js\";\nimport { isInBuilderFrame } from \"./builder-frame.js\";\nimport { useDevMode } from \"./use-dev-mode.js\";\nimport { getWorkspaceAppIdValidationError } from \"../shared/workspace-app-id.js\";\nimport { PromptComposer } from \"./composer/PromptComposer.js\";\n\nexport interface VaultSecretOption {\n id: string;\n name: string;\n credentialKey: string;\n provider?: string | null;\n description?: string | null;\n}\n\nexport interface NewWorkspaceAppFlowProps {\n sourceApp?: string;\n className?: string;\n dispatchBasePath?: string | null;\n}\n\nfunction slugify(value: string): string {\n return value\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .replace(/^[^a-z]+/, \"\")\n .slice(0, 48);\n}\n\nfunction titleFromPrompt(prompt: string): string {\n const cleaned = prompt\n .replace(/\\b(build|create|make|an?|the|app|tool|dashboard)\\b/gi, \" \")\n .replace(/\\s+/g, \" \")\n .trim();\n return slugify(cleaned || \"new-app\") || \"new-app\";\n}\n\nfunction actionUrl(basePath: string | null, action: string): string {\n const path = `/_agent-native/actions/${action}`;\n if (basePath === null) return agentNativePath(path);\n const normalized = basePath.replace(/\\/+$/, \"\");\n return `${normalized}${path}`;\n}\n\nfunction defaultDispatchBasePath(sourceApp?: string): string | null {\n if (sourceApp === \"dispatch\") return null;\n const base = appBasePath();\n if (base === \"/dispatch\") return null;\n return \"/dispatch\";\n}\n\nasync function fetchJson(url: string, init?: RequestInit): Promise<any> {\n const res = await fetch(url, init);\n const data = await res.json().catch(() => null);\n if (!res.ok) {\n throw new Error(\n data?.error || data?.message || `Request failed ${res.status}`,\n );\n }\n return data;\n}\n\nfunction buildNewWorkspaceAppPrompt(input: {\n appId: string;\n prompt: string;\n selectedKeys: string[];\n}): string {\n const keyList = input.selectedKeys.join(\", \");\n const grantRequest = keyList\n ? `Requested Dispatch vault key grants for this app: ${keyList}`\n : `Requested Dispatch vault key grants for this app: none`;\n\n return [\n `Create a new agent-native app in this workspace.`,\n `This is a new workspace app request, not a feature request for the current app.`,\n ``,\n `Suggested app name: ${input.appId} (you may adjust the slug if it conflicts)`,\n `User prompt: ${input.prompt.trim()}`,\n grantRequest,\n ``,\n `Pick a starter template that fits the user's prompt — analytics, calendar, content, design, dispatch, forms, mail, slides, clips, or starter when none of the others fit.`,\n `Use the workspace app layout: create it under apps/${input.appId}, mount it at /${input.appId}, keep it on the shared workspace database/hosting model, and avoid table-name collisions by namespacing any new domain tables to the app.`,\n `If the user's prompt mentions sibling apps like Mail, Calendar, Dispatch, or other templates, treat them as existing workspace neighbors or integrations. Do not scaffold those sibling apps inside apps/${input.appId} unless the user explicitly asks to create them too.`,\n `Do not satisfy this by adding a route, page, component, or file inside apps/starter or another existing app unless the user explicitly asks to modify that existing app.`,\n keyList\n ? `After the app exists, grant the selected Dispatch vault keys to appId \"${input.appId}\" and sync them once the app server is available. Treat these as requested grants, not active grants before creation succeeds.`\n : `Do not grant any Dispatch vault keys unless the user asks later.`,\n ``,\n `App readiness requirements before handing off:`,\n `- Update the workspace app registry metadata for \"${input.appId}\" (workspace-apps.json or .agent-native/workspace-apps.json, whichever this workspace uses) so Dispatch lists the app at /${input.appId} after merge/deploy.`,\n `- Update the app manifest/package/deploy metadata needed by the existing workspace deployment model; do not leave the app relying only on local discovery.`,\n `- Verify the app's agent card/A2A metadata is ready so Dispatch can discover and delegate to the app after deployment.`,\n `- Include a final verification note covering the registry entry, manifest/deploy metadata, and agent-card readiness.`,\n `When it is ready, start or update the workspace dev server and navigate the user to /${input.appId}.`,\n ].join(\"\\n\");\n}\n\nexport function NewWorkspaceAppFlow({\n sourceApp = \"starter\",\n className = \"\",\n dispatchBasePath,\n}: NewWorkspaceAppFlowProps) {\n const [selectedSecretIds, setSelectedSecretIds] = useState<string[]>([]);\n const [secrets, setSecrets] = useState<VaultSecretOption[]>([]);\n const [secretsError, setSecretsError] = useState<string | null>(null);\n const [statusMessage, setStatusMessage] = useState<string | null>(null);\n const [branchUrl, setBranchUrl] = useState<string | null>(null);\n const [isSubmitting, setIsSubmitting] = useState(false);\n const { isDevMode } = useDevMode();\n\n const effectiveDispatchBasePath =\n dispatchBasePath === undefined\n ? defaultDispatchBasePath(sourceApp)\n : dispatchBasePath;\n\n useEffect(() => {\n let cancelled = false;\n const url = actionUrl(\n effectiveDispatchBasePath,\n \"list-vault-secret-options\",\n );\n fetchJson(url)\n .then((data) => {\n if (cancelled) return;\n setSecrets(Array.isArray(data) ? data : []);\n setSecretsError(null);\n })\n .catch((err) => {\n if (cancelled) return;\n setSecrets([]);\n setSecretsError(err?.message || \"Could not load Dispatch keys\");\n });\n return () => {\n cancelled = true;\n };\n }, [effectiveDispatchBasePath]);\n\n const selectedSecrets = useMemo(\n () => secrets.filter((secret) => selectedSecretIds.includes(secret.id)),\n [secrets, selectedSecretIds],\n );\n const selectedSecretLabel =\n selectedSecretIds.length === 0\n ? \"No keys selected\"\n : `${selectedSecretIds.length} key${selectedSecretIds.length === 1 ? \"\" : \"s\"} selected`;\n\n async function submit(rawPrompt: string) {\n const prompt = rawPrompt.trim();\n if (!prompt || isSubmitting) return;\n const appId = titleFromPrompt(prompt);\n const validationError = getWorkspaceAppIdValidationError(appId);\n if (validationError) {\n setStatusMessage(validationError);\n return;\n }\n\n const message = buildNewWorkspaceAppPrompt({\n appId,\n prompt,\n selectedKeys: selectedSecrets.map((s) => s.credentialKey),\n });\n setIsSubmitting(true);\n setStatusMessage(null);\n setBranchUrl(null);\n\n try {\n if (isInBuilderFrame()) {\n sendToAgentChat({ message, submit: true, type: \"code\" });\n setStatusMessage(\"Sent to Builder chat.\");\n } else if (isDevMode) {\n sendToAgentChat({ message, submit: true, type: \"code\", newTab: true });\n setStatusMessage(\"Sent to the local agent.\");\n } else {\n const result = await fetchJson(\n actionUrl(effectiveDispatchBasePath, \"start-workspace-app-creation\"),\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n prompt,\n appId,\n secretIds: selectedSecretIds,\n }),\n },\n );\n if (result?.mode === \"builder\") {\n setBranchUrl(result?.url || null);\n setStatusMessage(\"Builder branch created.\");\n } else {\n setStatusMessage(\n result?.message ||\n \"Builder app creation is coming soon here. Open this workspace in Builder to create an app from this prompt.\",\n );\n }\n }\n } catch (err: any) {\n setStatusMessage(err?.message || \"Could not start the new app flow.\");\n } finally {\n setIsSubmitting(false);\n }\n }\n\n function toggleSecret(id: string) {\n setSelectedSecretIds((current) =>\n current.includes(id)\n ? current.filter((existing) => existing !== id)\n : [...current, id],\n );\n }\n\n return (\n <section\n className={`mx-auto flex w-full max-w-5xl flex-col gap-5 px-4 py-6 ${className}`}\n >\n <div className=\"grid gap-5 lg:grid-cols-[minmax(0,1fr)_320px]\">\n <div className=\"flex flex-col gap-3\">\n <PromptComposer\n autoFocus\n disabled={isSubmitting}\n placeholder=\"Describe the app your teammate should be able to use...\"\n draftScope=\"dispatch:new-app\"\n onSubmit={(text) => submit(text)}\n />\n\n {statusMessage ? (\n <div className=\"rounded-md border border-border bg-muted/40 px-3 py-2 text-sm text-muted-foreground\">\n {statusMessage}\n {branchUrl ? (\n <a\n href={branchUrl}\n target=\"_blank\"\n rel=\"noreferrer\"\n className=\"ml-2 inline-flex items-center gap-1 font-medium text-foreground underline\"\n >\n Open branch <IconArrowUpRight className=\"h-3 w-3\" />\n </a>\n ) : null}\n </div>\n ) : null}\n </div>\n\n <aside className=\"rounded-lg border border-border bg-card\">\n <div className=\"border-b border-border px-4 py-3\">\n <div className=\"flex items-center justify-between gap-3\">\n <div className=\"flex items-center gap-2 text-sm font-medium\">\n <IconKey className=\"h-4 w-4\" />\n Dispatch keys\n </div>\n <span className=\"shrink-0 rounded border border-border bg-background/40 px-2 py-0.5 text-[11px] text-muted-foreground\">\n {selectedSecretLabel}\n </span>\n </div>\n </div>\n <div className=\"max-h-[440px] space-y-2 overflow-y-auto p-3\">\n {secretsError ? (\n <p className=\"rounded-md border border-dashed border-border px-3 py-3 text-xs text-muted-foreground\">\n {secretsError}\n </p>\n ) : secrets.length === 0 ? (\n <p className=\"rounded-md border border-dashed border-border px-3 py-3 text-xs text-muted-foreground\">\n No Dispatch vault keys found yet.\n </p>\n ) : (\n secrets.map((secret) => {\n const selected = selectedSecretIds.includes(secret.id);\n return (\n <div\n key={secret.id}\n className={`group rounded-md border text-sm transition ${\n selected\n ? \"border-primary/45 bg-primary/5 text-foreground shadow-[inset_0_0_0_1px_hsl(var(--primary)/0.08)]\"\n : \"border-border bg-background/25 text-foreground hover:border-muted-foreground/40 hover:bg-accent/35\"\n }`}\n >\n <button\n type=\"button\"\n aria-pressed={selected}\n onClick={() => toggleSecret(secret.id)}\n className=\"flex w-full cursor-pointer items-start gap-3 rounded-md px-3 py-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/30\"\n >\n <span\n className={`mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded border transition ${\n selected\n ? \"border-primary/60 bg-primary/10 text-primary\"\n : \"border-muted-foreground/35 text-transparent group-hover:border-muted-foreground/60\"\n }`}\n >\n {selected ? <IconCheck className=\"h-3 w-3\" /> : null}\n </span>\n <span className=\"min-w-0 flex-1\">\n <span className=\"block truncate font-medium\">\n {secret.credentialKey}\n </span>\n <span className=\"block truncate text-xs text-muted-foreground/70\">\n {selected\n ? \"Will be requested for this app\"\n : \"Click to request\"}\n </span>\n </span>\n </button>\n <details className=\"group/details border-t border-border/60 px-3 py-1.5 text-xs text-muted-foreground/75 open:bg-background/10\">\n <summary className=\"flex cursor-pointer list-none items-center gap-1.5 text-[11px] hover:text-muted-foreground [&::-webkit-details-marker]:hidden\">\n <IconChevronDown className=\"h-3 w-3 transition-transform group-open/details:rotate-180\" />\n Details\n </summary>\n <div className=\"mt-1.5 space-y-1 pb-0.5 pl-4\">\n <div className=\"truncate\">\n Provider: {secret.provider || \"Not specified\"}\n </div>\n <div className=\"truncate\">Name: {secret.name}</div>\n </div>\n </details>\n </div>\n );\n })\n )}\n </div>\n </aside>\n </div>\n </section>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-chat-adapter.d.ts","sourceRoot":"","sources":["../../src/client/agent-chat-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAsB,MAAM,qBAAqB,CAAC;AAahF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-chat-adapter.d.ts","sourceRoot":"","sources":["../../src/client/agent-chat-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAsB,MAAM,qBAAqB,CAAC;AAahF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAuWrE;;;;GAIG;AACH;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,CAAC,EAAE;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAC3C,SAAS,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAC5C,SAAS,CAAC,EAAE;QAAE,OAAO,EAAE,eAAe,GAAG,SAAS,CAAA;KAAE,CAAC;IACrD,WAAW,CAAC,EAAE;QAAE,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;CACzD,GAAG,gBAAgB,CAoxBnB"}
|
|
@@ -39,6 +39,122 @@ function contentToContinuationHistory(content) {
|
|
|
39
39
|
}
|
|
40
40
|
return truncateForContinuation(chunks.join("\n\n"), 40_000).trim();
|
|
41
41
|
}
|
|
42
|
+
function messageTextFromContent(content) {
|
|
43
|
+
return content
|
|
44
|
+
.filter((p) => p.type === "text")
|
|
45
|
+
.map((p) => normalizeMentions(p.text))
|
|
46
|
+
.join("\n");
|
|
47
|
+
}
|
|
48
|
+
function isToolCallContentPart(part) {
|
|
49
|
+
return Boolean(part && typeof part === "object" && part.type === "tool-call");
|
|
50
|
+
}
|
|
51
|
+
function toolResultContent(result) {
|
|
52
|
+
if (typeof result === "string")
|
|
53
|
+
return result;
|
|
54
|
+
try {
|
|
55
|
+
return JSON.stringify(result);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return String(result ?? "");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function contentToStructuredMessages(content, nextToolCallId) {
|
|
62
|
+
const messages = [];
|
|
63
|
+
let assistantParts = [];
|
|
64
|
+
let pendingToolResults = [];
|
|
65
|
+
const flushToolTurn = () => {
|
|
66
|
+
if (pendingToolResults.length === 0)
|
|
67
|
+
return;
|
|
68
|
+
if (assistantParts.length > 0) {
|
|
69
|
+
messages.push({ role: "assistant", content: assistantParts });
|
|
70
|
+
}
|
|
71
|
+
messages.push({ role: "user", content: pendingToolResults });
|
|
72
|
+
assistantParts = [];
|
|
73
|
+
pendingToolResults = [];
|
|
74
|
+
};
|
|
75
|
+
for (const part of content) {
|
|
76
|
+
if (part.type === "text") {
|
|
77
|
+
if (pendingToolResults.length > 0)
|
|
78
|
+
flushToolTurn();
|
|
79
|
+
if (part.text.trim()) {
|
|
80
|
+
assistantParts.push({ type: "text", text: part.text });
|
|
81
|
+
}
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (isToolCallContentPart(part)) {
|
|
85
|
+
const toolCallId = nextToolCallId();
|
|
86
|
+
assistantParts.push({
|
|
87
|
+
type: "tool-call",
|
|
88
|
+
toolCallId,
|
|
89
|
+
toolName: part.toolName,
|
|
90
|
+
args: part.args ?? {},
|
|
91
|
+
});
|
|
92
|
+
if (part.result !== undefined) {
|
|
93
|
+
pendingToolResults.push({
|
|
94
|
+
type: "tool-result",
|
|
95
|
+
toolCallId,
|
|
96
|
+
toolName: part.toolName,
|
|
97
|
+
content: toolResultContent(part.result),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
flushToolTurn();
|
|
103
|
+
if (assistantParts.length > 0) {
|
|
104
|
+
messages.push({ role: "assistant", content: assistantParts });
|
|
105
|
+
}
|
|
106
|
+
return messages;
|
|
107
|
+
}
|
|
108
|
+
function assistantUiMessagesToStructuredHistory(messages) {
|
|
109
|
+
let nextId = 0;
|
|
110
|
+
const nextToolCallId = () => `history_tc_${++nextId}`;
|
|
111
|
+
const structured = [];
|
|
112
|
+
for (const message of messages) {
|
|
113
|
+
if (message.role === "user") {
|
|
114
|
+
const text = messageTextFromContent(message.content);
|
|
115
|
+
if (text.trim()) {
|
|
116
|
+
structured.push({
|
|
117
|
+
role: "user",
|
|
118
|
+
content: [{ type: "text", text }],
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (message.role !== "assistant")
|
|
124
|
+
continue;
|
|
125
|
+
const content = [];
|
|
126
|
+
for (const part of message.content) {
|
|
127
|
+
if (part?.type === "text" && typeof part.text === "string") {
|
|
128
|
+
content.push({ type: "text", text: part.text });
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (part?.type === "tool-call") {
|
|
132
|
+
content.push({
|
|
133
|
+
type: "tool-call",
|
|
134
|
+
toolCallId: typeof part.toolCallId === "string" ? part.toolCallId : "",
|
|
135
|
+
toolName: typeof part.toolName === "string"
|
|
136
|
+
? part.toolName
|
|
137
|
+
: typeof part.toolName === "undefined"
|
|
138
|
+
? "unknown"
|
|
139
|
+
: String(part.toolName),
|
|
140
|
+
argsText: typeof part.argsText === "string"
|
|
141
|
+
? part.argsText
|
|
142
|
+
: JSON.stringify(part.args ?? {}),
|
|
143
|
+
args: part.args &&
|
|
144
|
+
typeof part.args === "object" &&
|
|
145
|
+
!Array.isArray(part.args)
|
|
146
|
+
? part.args
|
|
147
|
+
: {},
|
|
148
|
+
...(part.result !== undefined
|
|
149
|
+
? { result: toolResultContent(part.result) }
|
|
150
|
+
: {}),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
structured.push(...contentToStructuredMessages(content, nextToolCallId));
|
|
155
|
+
}
|
|
156
|
+
return structured;
|
|
157
|
+
}
|
|
42
158
|
function combineContinuationHistory(fragments) {
|
|
43
159
|
return truncateForContinuation(fragments.filter(Boolean).join("\n\n"), 40_000).trim();
|
|
44
160
|
}
|
|
@@ -246,17 +362,15 @@ export function createAgentChatAdapter(options) {
|
|
|
246
362
|
const userMessageText = rawMessageText.trim() || attachments.length === 0
|
|
247
363
|
? rawMessageText
|
|
248
364
|
: "Use the attached context.";
|
|
249
|
-
const
|
|
250
|
-
|
|
365
|
+
const priorMessages = messages.slice(0, -1); // exclude latest user message
|
|
366
|
+
const history = priorMessages
|
|
251
367
|
.filter((m) => m.role === "user" || m.role === "assistant")
|
|
252
368
|
.map((m) => ({
|
|
253
369
|
role: m.role,
|
|
254
|
-
content: m.content
|
|
255
|
-
.filter((p) => p.type === "text")
|
|
256
|
-
.map((p) => p.text.replace(/@\[([^\]|]+)\|[^\]]+\]/g, "@$1"))
|
|
257
|
-
.join("\n"),
|
|
370
|
+
content: messageTextFromContent(m.content),
|
|
258
371
|
}))
|
|
259
372
|
.filter((m) => m.content.trim());
|
|
373
|
+
const structuredHistory = assistantUiMessagesToStructuredHistory(priorMessages);
|
|
260
374
|
// Signal that generation is starting
|
|
261
375
|
if (typeof window !== "undefined") {
|
|
262
376
|
window.dispatchEvent(new CustomEvent("agentNative.chatRunning", {
|
|
@@ -269,6 +383,7 @@ export function createAgentChatAdapter(options) {
|
|
|
269
383
|
let lastSeq = -1;
|
|
270
384
|
let currentMessageText = normalizeMentions(userMessageText);
|
|
271
385
|
let currentHistory = history;
|
|
386
|
+
let currentStructuredHistory = structuredHistory;
|
|
272
387
|
let includeAttachments = attachments.length > 0;
|
|
273
388
|
let includeReferences = Boolean(runConfig?.custom?.references);
|
|
274
389
|
let startupRecoveryAttempts = 0;
|
|
@@ -276,10 +391,13 @@ export function createAgentChatAdapter(options) {
|
|
|
276
391
|
let stalledTransientContinuationAttempts = 0;
|
|
277
392
|
let totalTransientContinuationAttempts = 0;
|
|
278
393
|
const continuationHistoryFragments = [];
|
|
394
|
+
const structuredContinuationFragments = [];
|
|
279
395
|
let visibleContinuationPrefix = [];
|
|
280
396
|
let lastAutoContinueReason = null;
|
|
281
397
|
const attemptedRunIds = [];
|
|
282
398
|
let authRecoveryAttempted = false;
|
|
399
|
+
let continuationToolCallCounter = 0;
|
|
400
|
+
const nextContinuationToolCallId = () => `continuation_tc_${++continuationToolCallCounter}`;
|
|
283
401
|
const connectionRecoveryDetails = () => {
|
|
284
402
|
return [
|
|
285
403
|
lastAutoContinueReason
|
|
@@ -299,7 +417,11 @@ export function createAgentChatAdapter(options) {
|
|
|
299
417
|
if (typeof window === "undefined")
|
|
300
418
|
return;
|
|
301
419
|
window.dispatchEvent(new CustomEvent("agent-chat:auth-error", {
|
|
302
|
-
detail: {
|
|
420
|
+
detail: {
|
|
421
|
+
reason,
|
|
422
|
+
...(tabId ? { tabId } : {}),
|
|
423
|
+
...(threadId ? { threadId } : {}),
|
|
424
|
+
},
|
|
303
425
|
}));
|
|
304
426
|
};
|
|
305
427
|
const tryRecoverAuthOnce = async () => {
|
|
@@ -461,6 +583,13 @@ export function createAgentChatAdapter(options) {
|
|
|
461
583
|
const partialHistory = combineContinuationHistory(isTransient
|
|
462
584
|
? continuationHistoryFragments
|
|
463
585
|
: [...continuationHistoryFragments, currentPartialHistory]);
|
|
586
|
+
const structuredPartialHistory = contentToStructuredMessages(visibleContent, nextContinuationToolCallId);
|
|
587
|
+
if (isTransient && structuredPartialHistory.length > 0) {
|
|
588
|
+
structuredContinuationFragments.push(...structuredPartialHistory);
|
|
589
|
+
}
|
|
590
|
+
const structuredCombinedHistory = isTransient
|
|
591
|
+
? structuredContinuationFragments
|
|
592
|
+
: [...structuredContinuationFragments, ...structuredPartialHistory];
|
|
464
593
|
currentHistory = [
|
|
465
594
|
...history,
|
|
466
595
|
{ role: "user", content: normalizeMentions(userMessageText) },
|
|
@@ -468,6 +597,16 @@ export function createAgentChatAdapter(options) {
|
|
|
468
597
|
? [{ role: "assistant", content: partialHistory }]
|
|
469
598
|
: []),
|
|
470
599
|
];
|
|
600
|
+
currentStructuredHistory = [
|
|
601
|
+
...structuredHistory,
|
|
602
|
+
{
|
|
603
|
+
role: "user",
|
|
604
|
+
content: [
|
|
605
|
+
{ type: "text", text: normalizeMentions(userMessageText) },
|
|
606
|
+
],
|
|
607
|
+
},
|
|
608
|
+
...structuredCombinedHistory,
|
|
609
|
+
];
|
|
471
610
|
currentMessageText = autoContinueMessage(signal);
|
|
472
611
|
includeAttachments = false;
|
|
473
612
|
includeReferences = false;
|
|
@@ -491,6 +630,7 @@ export function createAgentChatAdapter(options) {
|
|
|
491
630
|
body: JSON.stringify({
|
|
492
631
|
message: currentMessageText,
|
|
493
632
|
history: currentHistory,
|
|
633
|
+
structuredHistory: currentStructuredHistory,
|
|
494
634
|
...(threadId ? { threadId } : {}),
|
|
495
635
|
...(requestMode ? { mode: requestMode } : {}),
|
|
496
636
|
...(modelRef?.current ? { model: modelRef.current } : {}),
|