@zk-tech/ag-ui-core 0.0.1-alpha.1 → 0.0.1-alpha.10

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/README.md CHANGED
@@ -1,24 +1,43 @@
1
- # lv-bedrock
1
+ # @zk-tech/ag-ui-core
2
2
 
3
- ## Get Started
3
+ Extends from AG-UI core with more strict types and project-specific utilities.
4
4
 
5
- 按开发环境的要求,运行和调试项目
5
+ ## Development Setup
6
6
 
7
- 运行和调试组件
7
+ ### Using npm link for local development
8
8
 
9
- ```
10
- pnpm run dev
11
- ```
9
+ 1. **Build the package:**
10
+ ```bash
11
+ cd web-package/packages/ag-ui-core
12
+ pnpm build
13
+ ```
12
14
 
13
- 按照社区规范和最佳实践,生成构建产物
15
+ 2. **Create npm link:**
16
+ ```bash
17
+ npm link
18
+ ```
14
19
 
15
- ```
16
- pnpm run build
17
- ```
20
+ 3. **Link in consuming project:**
21
+ ```bash
22
+ cd ../../../zk-web
23
+ npm link @zk-tech/ag-ui-core
24
+ ```
18
25
 
19
- 继续创建更多项目要素
26
+ 4. **Unlink when done (optional):**
27
+ ```bash
28
+ # In consuming project
29
+ npm unlink @zk-tech/ag-ui-core
30
+
31
+ # In package directory
32
+ npm unlink
33
+ ```
20
34
 
21
- ```
22
- pnpm run new
23
- ```
35
+ ## Usage
24
36
 
37
+ ```typescript
38
+ import { createProjectContext } from '@zk-tech/ag-ui-core/utils';
39
+ import { DesignProjectCtxNamespace, type DesignProjectProjectCtx } from '@zk-tech/ag-ui-core/protocol';
40
+
41
+ // Create project context
42
+ const context = createProjectContext('project-id-123');
43
+ ```
@@ -0,0 +1,17 @@
1
+ declare enum DesignProjectCtxNamespace {
2
+ Project = "project"
3
+ }
4
+ interface DesignProjectProjectCtx {
5
+ projectId: string;
6
+ /** 草稿版本号, 如果没有那么则传递 undefined */
7
+ workspaceHash: string | undefined;
8
+ }
9
+ declare enum AgentConfigCtxNamespace {
10
+ Config = "agent-config"
11
+ }
12
+ interface AgentConfigCtx {
13
+ /** 模型类型,对应 ModelType 枚举值 */
14
+ modelType: number;
15
+ }
16
+
17
+ export { AgentConfigCtxNamespace as A, DesignProjectCtxNamespace as D, type DesignProjectProjectCtx as a, type AgentConfigCtx as b };
@@ -0,0 +1,17 @@
1
+ declare enum DesignProjectCtxNamespace {
2
+ Project = "project"
3
+ }
4
+ interface DesignProjectProjectCtx {
5
+ projectId: string;
6
+ /** 草稿版本号, 如果没有那么则传递 undefined */
7
+ workspaceHash: string | undefined;
8
+ }
9
+ declare enum AgentConfigCtxNamespace {
10
+ Config = "agent-config"
11
+ }
12
+ interface AgentConfigCtx {
13
+ /** 模型类型,对应 ModelType 枚举值 */
14
+ modelType: number;
15
+ }
16
+
17
+ export { AgentConfigCtxNamespace as A, DesignProjectCtxNamespace as D, type DesignProjectProjectCtx as a, type AgentConfigCtx as b };
package/dist/index.cjs CHANGED
@@ -1,11 +1,87 @@
1
1
  'use strict';
2
2
 
3
+ var zod = require('zod');
4
+
3
5
  // src/protocol/context.ts
4
6
  var DesignProjectCtxNamespace = /* @__PURE__ */ ((DesignProjectCtxNamespace2) => {
5
7
  DesignProjectCtxNamespace2["Project"] = "project";
6
8
  return DesignProjectCtxNamespace2;
7
9
  })(DesignProjectCtxNamespace || {});
10
+ var AgentConfigCtxNamespace = /* @__PURE__ */ ((AgentConfigCtxNamespace2) => {
11
+ AgentConfigCtxNamespace2["Config"] = "agent-config";
12
+ return AgentConfigCtxNamespace2;
13
+ })(AgentConfigCtxNamespace || {});
14
+ function isAssistantContentParts(content) {
15
+ return Array.isArray(content);
16
+ }
17
+ function isAssistantMessageWithParts(msg) {
18
+ return msg.role === "assistant" && Array.isArray(msg.content);
19
+ }
20
+ var AssistantMessageMetadataSchema = zod.z.object({
21
+ runId: zod.z.string().optional(),
22
+ parentRunId: zod.z.string().optional(),
23
+ traceUrl: zod.z.string().optional()
24
+ });
25
+
26
+ // src/utils/is-project-ctx.ts
27
+ function isDesignProjectProjectCtx(value) {
28
+ return typeof value === "object" && value !== null && "projectId" in value && typeof value.projectId === "string" && value.projectId.length > 0;
29
+ }
30
+
31
+ // src/utils/create-project-context.ts
32
+ function createProjectContext(ctx) {
33
+ return {
34
+ description: "project" /* Project */,
35
+ value: JSON.stringify(ctx)
36
+ };
37
+ }
38
+
39
+ // src/utils/extract-workspace-hash-from-context.ts
40
+ function extractWorkspaceHashFromContext(context) {
41
+ if (!context || !Array.isArray(context)) {
42
+ return void 0;
43
+ }
44
+ for (const ctx of context) {
45
+ if (!ctx || typeof ctx !== "object") {
46
+ continue;
47
+ }
48
+ const namespace = ctx.description;
49
+ if (namespace === "project" /* Project */ && ctx.value) {
50
+ try {
51
+ const parsed = typeof ctx.value === "string" ? JSON.parse(ctx.value) : ctx.value;
52
+ if (isDesignProjectProjectCtx(parsed)) {
53
+ return parsed.workspaceHash;
54
+ }
55
+ } catch {
56
+ continue;
57
+ }
58
+ }
59
+ }
60
+ return void 0;
61
+ }
62
+
63
+ // src/utils/is-agent-config-ctx.ts
64
+ function isAgentConfigCtx(value) {
65
+ return typeof value === "object" && value !== null && "modelType" in value && typeof value.modelType === "number";
66
+ }
67
+
68
+ // src/utils/create-agent-config-context.ts
69
+ function createAgentConfigContext(ctx) {
70
+ return {
71
+ description: "agent-config" /* Config */,
72
+ value: JSON.stringify(ctx)
73
+ };
74
+ }
8
75
 
76
+ exports.AgentConfigCtxNamespace = AgentConfigCtxNamespace;
77
+ exports.AssistantMessageMetadataSchema = AssistantMessageMetadataSchema;
9
78
  exports.DesignProjectCtxNamespace = DesignProjectCtxNamespace;
79
+ exports.createAgentConfigContext = createAgentConfigContext;
80
+ exports.createProjectContext = createProjectContext;
81
+ exports.extractWorkspaceHashFromContext = extractWorkspaceHashFromContext;
82
+ exports.isAgentConfigCtx = isAgentConfigCtx;
83
+ exports.isAssistantContentParts = isAssistantContentParts;
84
+ exports.isAssistantMessageWithParts = isAssistantMessageWithParts;
85
+ exports.isDesignProjectProjectCtx = isDesignProjectProjectCtx;
10
86
  //# sourceMappingURL=index.cjs.map
11
87
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/protocol/context.ts"],"names":["DesignProjectCtxNamespace"],"mappings":";;;AACO,IAAK,yBAAA,qBAAAA,0BAAAA,KAAL;AAEH,EAAAA,2BAAA,SAAA,CAAA,GAAU,SAAA;AAFF,EAAA,OAAAA,0BAAAA;AAAA,CAAA,EAAA,yBAAA,IAAA,EAAA","file":"index.cjs","sourcesContent":["\nexport enum DesignProjectCtxNamespace {\n // 项目相关上下文\n Project = 'project',\n}\n\nexport interface DesignProjectProjectCtx {\n projectId: string;\n}"]}
1
+ {"version":3,"sources":["../src/protocol/context.ts","../src/protocol/message.ts","../src/utils/is-project-ctx.ts","../src/utils/create-project-context.ts","../src/utils/extract-workspace-hash-from-context.ts","../src/utils/is-agent-config-ctx.ts","../src/utils/create-agent-config-context.ts"],"names":["DesignProjectCtxNamespace","AgentConfigCtxNamespace","z"],"mappings":";;;;;AACO,IAAK,yBAAA,qBAAAA,0BAAAA,KAAL;AAEH,EAAAA,2BAAA,SAAA,CAAA,GAAU,SAAA;AAFF,EAAA,OAAAA,0BAAAA;AAAA,CAAA,EAAA,yBAAA,IAAA,EAAA;AAWL,IAAK,uBAAA,qBAAAC,wBAAAA,KAAL;AAEH,EAAAA,yBAAA,QAAA,CAAA,GAAS,cAAA;AAFD,EAAA,OAAAA,wBAAAA;AAAA,CAAA,EAAA,uBAAA,IAAA,EAAA;ACyCL,SAAS,wBACd,OAAA,EACmC;AACnC,EAAA,OAAO,KAAA,CAAM,QAAQ,OAAO,CAAA;AAC9B;AAaO,SAAS,4BACd,GAAA,EAC6E;AAC7E,EAAA,OAAO,IAAI,IAAA,KAAS,WAAA,IAAe,KAAA,CAAM,OAAA,CAAQ,IAAI,OAAO,CAAA;AAC9D;AAMO,IAAM,8BAAA,GAAiCC,MAAE,MAAA,CAAO;AAAA,EACrD,KAAA,EAAOA,KAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC3B,WAAA,EAAaA,KAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EACjC,QAAA,EAAUA,KAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AACvB,CAAC;;;AC/EM,SAAS,0BAA0B,KAAA,EAAkD;AACxF,EAAA,OACE,OAAO,KAAA,KAAU,QAAA,IACjB,KAAA,KAAU,IAAA,IACV,WAAA,IAAe,KAAA,IACf,OAAQ,KAAA,CAAkC,SAAA,KAAc,QAAA,IACvD,KAAA,CAAkC,UAAU,MAAA,GAAS,CAAA;AAE1D;;;ACDK,SAAS,qBAAqB,GAAA,EAAuC;AAE1E,EAAA,OAAO;AAAA,IACL,WAAA,EAAA,SAAA;AAAA,IACA,KAAA,EAAO,IAAA,CAAK,SAAA,CAAU,GAAG;AAAA,GAC3B;AACF;;;ACJO,SAAS,gCACd,OAAA,EACoB;AACpB,EAAA,IAAI,CAAC,OAAA,IAAW,CAAC,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA,EAAG;AACvC,IAAA,OAAO,MAAA;AAAA,EACT;AAGA,EAAA,KAAA,MAAW,OAAO,OAAA,EAAS;AACzB,IAAA,IAAI,CAAC,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAA,EAAU;AACnC,MAAA;AAAA,IACF;AAGA,IAAA,MAAM,YAAY,GAAA,CAAI,WAAA;AACtB,IAAA,IAAI,SAAA,KAAA,SAAA,kBAAmD,IAAI,KAAA,EAAO;AAChE,MAAA,IAAI;AAEF,QAAA,MAAM,MAAA,GAAS,OAAO,GAAA,CAAI,KAAA,KAAU,QAAA,GAAW,KAAK,KAAA,CAAM,GAAA,CAAI,KAAK,CAAA,GAAI,GAAA,CAAI,KAAA;AAG3E,QAAA,IAAI,yBAAA,CAA0B,MAAM,CAAA,EAAG;AACrC,UAAA,OAAO,MAAA,CAAO,aAAA;AAAA,QAChB;AAAA,MACF,CAAA,CAAA,MAAQ;AAEN,QAAA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT;;;ACzCO,SAAS,iBAAiB,KAAA,EAAyC;AACxE,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,WAAA,IAAe,KAAA,IACf,OAAQ,KAAA,CAAkC,SAAA,KAAc,QAAA;AAE5D;;;ACAO,SAAS,yBAAyB,GAAA,EAA8B;AACrE,EAAA,OAAO;AAAA,IACL,WAAA,EAAA,cAAA;AAAA,IACA,KAAA,EAAO,IAAA,CAAK,SAAA,CAAU,GAAG;AAAA,GAC3B;AACF","file":"index.cjs","sourcesContent":["\nexport enum DesignProjectCtxNamespace {\n // 项目相关上下文\n Project = 'project',\n}\n\nexport interface DesignProjectProjectCtx {\n projectId: string;\n /** 草稿版本号, 如果没有那么则传递 undefined */\n workspaceHash: string | undefined;\n}\n\nexport enum AgentConfigCtxNamespace {\n // Agent 配置相关上下文\n Config = 'agent-config',\n}\n\nexport interface AgentConfigCtx {\n /** 模型类型,对应 ModelType 枚举值 */\n modelType: number;\n}\n","import { z } from \"zod\";\nimport type { Message as BaseMessage } from \"@ag-ui/core\";\n\n/**\n * Assistant message content part: thinking (reasoning) block.\n */\nexport interface AssistantContentPartThinking {\n type: \"thinking\";\n text: string;\n}\n\n/**\n * Assistant message content part: main answer text.\n */\nexport interface AssistantContentPartAnswer {\n type: \"answer\";\n text: string;\n}\n\n/**\n * Assistant message content part: inspire questions.\n */\nexport interface AssistantContentPartInspireQuestions {\n type: \"inspire_questions\";\n questions: string[];\n}\n\n/**\n * Assistant message content part: ask to continue prompt.\n */\nexport interface AssistantContentPartAskToContinue {\n type: \"ask_to_continue\";\n text: string;\n}\n\n/**\n * Discriminated union of all assistant content part types.\n */\nexport type AssistantContentPart =\n | AssistantContentPartThinking\n | AssistantContentPartAnswer\n | AssistantContentPartInspireQuestions\n | AssistantContentPartAskToContinue;\n\n/**\n * Assistant message content: either plain string (legacy/compat) or structured parts.\n * When string, treat as normal LLM response.\n */\nexport type AssistantMessageContent = string | AssistantContentPart[];\n\n/**\n * Type guard: content is array of parts (not plain string).\n */\nexport function isAssistantContentParts(\n content: AssistantMessageContent\n): content is AssistantContentPart[] {\n return Array.isArray(content);\n}\n\n/**\n * Message with extended assistant content (string | AssistantContentPart[]).\n * Other roles keep content as string; assistant may use AssistantMessageContent.\n */\nexport type Message =\n | (BaseMessage & { role: \"assistant\"; content: AssistantMessageContent })\n | (BaseMessage & { role?: \"user\" | \"tool\" | \"system\" });\n\n/**\n * Type guard: message is assistant with content parts.\n */\nexport function isAssistantMessageWithParts(\n msg: Message\n): msg is BaseMessage & { role: \"assistant\"; content: AssistantContentPart[] } {\n return msg.role === \"assistant\" && Array.isArray(msg.content);\n}\n\n/**\n * Metadata for assistant messages (business fields only).\n * Content semantics (thinking, inspire_questions, etc.) live in message.content as AssistantContentPart[].\n */\nexport const AssistantMessageMetadataSchema = z.object({\n runId: z.string().optional(),\n parentRunId: z.string().optional(),\n traceUrl: z.string().optional(),\n});\n\nexport type AssistantMessageMetadata = z.infer<typeof AssistantMessageMetadataSchema>;\n","/**\n * Type guard to check if an object matches DesignProjectProjectCtx\n */\nimport { type DesignProjectProjectCtx } from '../protocol';\n\nexport function isDesignProjectProjectCtx(value: unknown): value is DesignProjectProjectCtx {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'projectId' in value &&\n typeof (value as Record<string, unknown>).projectId === 'string' &&\n (value as DesignProjectProjectCtx).projectId.length > 0\n );\n }\n ","/**\n * Create project context for AG-UI RunAgentInput\n */\nimport { type DesignProjectProjectCtx, DesignProjectCtxNamespace } from '../protocol';\nimport type { Context } from '@ag-ui/core';\n\n/**\n * Create a project context item for AG-UI RunAgentInput\n *\n * @param projectId - The project ID\n * @returns Context item with namespace 'project' and projectId in value\n */\nexport function createProjectContext(ctx: DesignProjectProjectCtx): Context {\n // const projectCtx: DesignProjectProjectCtx = { projectId, workspaceHash };\n return {\n description: DesignProjectCtxNamespace.Project,\n value: JSON.stringify(ctx),\n };\n}\n","/**\n * Extract workspaceHash from context array\n * Looks for context with namespace 'project' and extracts workspaceHash from value\n */\nimport { type DesignProjectProjectCtx, DesignProjectCtxNamespace } from '../protocol';\nimport { isDesignProjectProjectCtx } from './is-project-ctx';\n\n/**\n * Extract workspaceHash from context array\n * Looks for context with namespace 'project' and extracts workspaceHash from value\n *\n * @param context - Context array from RunAgentInput\n * @returns workspaceHash if found, undefined otherwise\n */\nexport function extractWorkspaceHashFromContext(\n context: Array<{ description?: string; value?: string }> | undefined\n): string | undefined {\n if (!context || !Array.isArray(context)) {\n return undefined;\n }\n\n // Look for context with namespace 'project'\n for (const ctx of context) {\n if (!ctx || typeof ctx !== 'object') {\n continue;\n }\n\n // Check if this is a project context (namespace = 'project')\n const namespace = ctx.description;\n if (namespace === DesignProjectCtxNamespace.Project && ctx.value) {\n try {\n // Parse value as JSON (AG-UI Context.value is a string)\n const parsed = typeof ctx.value === 'string' ? JSON.parse(ctx.value) : ctx.value;\n\n // Use type guard to validate and extract workspaceHash with proper typing\n if (isDesignProjectProjectCtx(parsed)) {\n return parsed.workspaceHash;\n }\n } catch {\n // Invalid JSON, skip this context\n continue;\n }\n }\n }\n\n return undefined;\n}","/**\n * Type guard to check if an object matches AgentConfigCtx\n */\nimport { type AgentConfigCtx } from '../protocol';\n\nexport function isAgentConfigCtx(value: unknown): value is AgentConfigCtx {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'modelType' in value &&\n typeof (value as Record<string, unknown>).modelType === 'number'\n );\n}\n","/**\n * Create agent config context for AG-UI RunAgentInput\n */\nimport { type AgentConfigCtx, AgentConfigCtxNamespace } from '../protocol';\nimport type { Context } from '@ag-ui/core';\n\n/**\n * Create an agent config context item for AG-UI RunAgentInput\n *\n * @param ctx - The agent config context containing modelType\n * @returns Context item with namespace 'agent-config' and modelType in value\n */\nexport function createAgentConfigContext(ctx: AgentConfigCtx): Context {\n return {\n description: AgentConfigCtxNamespace.Config,\n value: JSON.stringify(ctx),\n };\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -1 +1,5 @@
1
- export { DesignProjectCtxNamespace, DesignProjectProjectCtx } from './protocol/index.cjs';
1
+ export { b as AgentConfigCtx, A as AgentConfigCtxNamespace, D as DesignProjectCtxNamespace, a as DesignProjectProjectCtx } from './context-CRBz7KR8.cjs';
2
+ export { AssistantContentPart, AssistantContentPartAnswer, AssistantContentPartAskToContinue, AssistantContentPartInspireQuestions, AssistantContentPartThinking, AssistantMessageContent, AssistantMessageMetadata, AssistantMessageMetadataSchema, Message, ResumeOption, RunAgentInput, isAssistantContentParts, isAssistantMessageWithParts } from './protocol/index.cjs';
3
+ export { createAgentConfigContext, createProjectContext, extractWorkspaceHashFromContext, isAgentConfigCtx, isDesignProjectProjectCtx } from './utils/index.cjs';
4
+ import 'zod';
5
+ import '@ag-ui/core';
package/dist/index.d.ts CHANGED
@@ -1 +1,5 @@
1
- export { DesignProjectCtxNamespace, DesignProjectProjectCtx } from './protocol/index.js';
1
+ export { b as AgentConfigCtx, A as AgentConfigCtxNamespace, D as DesignProjectCtxNamespace, a as DesignProjectProjectCtx } from './context-CRBz7KR8.js';
2
+ export { AssistantContentPart, AssistantContentPartAnswer, AssistantContentPartAskToContinue, AssistantContentPartInspireQuestions, AssistantContentPartThinking, AssistantMessageContent, AssistantMessageMetadata, AssistantMessageMetadataSchema, Message, ResumeOption, RunAgentInput, isAssistantContentParts, isAssistantMessageWithParts } from './protocol/index.js';
3
+ export { createAgentConfigContext, createProjectContext, extractWorkspaceHashFromContext, isAgentConfigCtx, isDesignProjectProjectCtx } from './utils/index.js';
4
+ import 'zod';
5
+ import '@ag-ui/core';
package/dist/index.js CHANGED
@@ -1,9 +1,76 @@
1
+ import { z } from 'zod';
2
+
1
3
  // src/protocol/context.ts
2
4
  var DesignProjectCtxNamespace = /* @__PURE__ */ ((DesignProjectCtxNamespace2) => {
3
5
  DesignProjectCtxNamespace2["Project"] = "project";
4
6
  return DesignProjectCtxNamespace2;
5
7
  })(DesignProjectCtxNamespace || {});
8
+ var AgentConfigCtxNamespace = /* @__PURE__ */ ((AgentConfigCtxNamespace2) => {
9
+ AgentConfigCtxNamespace2["Config"] = "agent-config";
10
+ return AgentConfigCtxNamespace2;
11
+ })(AgentConfigCtxNamespace || {});
12
+ function isAssistantContentParts(content) {
13
+ return Array.isArray(content);
14
+ }
15
+ function isAssistantMessageWithParts(msg) {
16
+ return msg.role === "assistant" && Array.isArray(msg.content);
17
+ }
18
+ var AssistantMessageMetadataSchema = z.object({
19
+ runId: z.string().optional(),
20
+ parentRunId: z.string().optional(),
21
+ traceUrl: z.string().optional()
22
+ });
23
+
24
+ // src/utils/is-project-ctx.ts
25
+ function isDesignProjectProjectCtx(value) {
26
+ return typeof value === "object" && value !== null && "projectId" in value && typeof value.projectId === "string" && value.projectId.length > 0;
27
+ }
28
+
29
+ // src/utils/create-project-context.ts
30
+ function createProjectContext(ctx) {
31
+ return {
32
+ description: "project" /* Project */,
33
+ value: JSON.stringify(ctx)
34
+ };
35
+ }
36
+
37
+ // src/utils/extract-workspace-hash-from-context.ts
38
+ function extractWorkspaceHashFromContext(context) {
39
+ if (!context || !Array.isArray(context)) {
40
+ return void 0;
41
+ }
42
+ for (const ctx of context) {
43
+ if (!ctx || typeof ctx !== "object") {
44
+ continue;
45
+ }
46
+ const namespace = ctx.description;
47
+ if (namespace === "project" /* Project */ && ctx.value) {
48
+ try {
49
+ const parsed = typeof ctx.value === "string" ? JSON.parse(ctx.value) : ctx.value;
50
+ if (isDesignProjectProjectCtx(parsed)) {
51
+ return parsed.workspaceHash;
52
+ }
53
+ } catch {
54
+ continue;
55
+ }
56
+ }
57
+ }
58
+ return void 0;
59
+ }
60
+
61
+ // src/utils/is-agent-config-ctx.ts
62
+ function isAgentConfigCtx(value) {
63
+ return typeof value === "object" && value !== null && "modelType" in value && typeof value.modelType === "number";
64
+ }
65
+
66
+ // src/utils/create-agent-config-context.ts
67
+ function createAgentConfigContext(ctx) {
68
+ return {
69
+ description: "agent-config" /* Config */,
70
+ value: JSON.stringify(ctx)
71
+ };
72
+ }
6
73
 
7
- export { DesignProjectCtxNamespace };
74
+ export { AgentConfigCtxNamespace, AssistantMessageMetadataSchema, DesignProjectCtxNamespace, createAgentConfigContext, createProjectContext, extractWorkspaceHashFromContext, isAgentConfigCtx, isAssistantContentParts, isAssistantMessageWithParts, isDesignProjectProjectCtx };
8
75
  //# sourceMappingURL=index.js.map
9
76
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/protocol/context.ts"],"names":["DesignProjectCtxNamespace"],"mappings":";AACO,IAAK,yBAAA,qBAAAA,0BAAAA,KAAL;AAEH,EAAAA,2BAAA,SAAA,CAAA,GAAU,SAAA;AAFF,EAAA,OAAAA,0BAAAA;AAAA,CAAA,EAAA,yBAAA,IAAA,EAAA","file":"index.js","sourcesContent":["\nexport enum DesignProjectCtxNamespace {\n // 项目相关上下文\n Project = 'project',\n}\n\nexport interface DesignProjectProjectCtx {\n projectId: string;\n}"]}
1
+ {"version":3,"sources":["../src/protocol/context.ts","../src/protocol/message.ts","../src/utils/is-project-ctx.ts","../src/utils/create-project-context.ts","../src/utils/extract-workspace-hash-from-context.ts","../src/utils/is-agent-config-ctx.ts","../src/utils/create-agent-config-context.ts"],"names":["DesignProjectCtxNamespace","AgentConfigCtxNamespace"],"mappings":";;;AACO,IAAK,yBAAA,qBAAAA,0BAAAA,KAAL;AAEH,EAAAA,2BAAA,SAAA,CAAA,GAAU,SAAA;AAFF,EAAA,OAAAA,0BAAAA;AAAA,CAAA,EAAA,yBAAA,IAAA,EAAA;AAWL,IAAK,uBAAA,qBAAAC,wBAAAA,KAAL;AAEH,EAAAA,yBAAA,QAAA,CAAA,GAAS,cAAA;AAFD,EAAA,OAAAA,wBAAAA;AAAA,CAAA,EAAA,uBAAA,IAAA,EAAA;ACyCL,SAAS,wBACd,OAAA,EACmC;AACnC,EAAA,OAAO,KAAA,CAAM,QAAQ,OAAO,CAAA;AAC9B;AAaO,SAAS,4BACd,GAAA,EAC6E;AAC7E,EAAA,OAAO,IAAI,IAAA,KAAS,WAAA,IAAe,KAAA,CAAM,OAAA,CAAQ,IAAI,OAAO,CAAA;AAC9D;AAMO,IAAM,8BAAA,GAAiC,EAAE,MAAA,CAAO;AAAA,EACrD,KAAA,EAAO,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC3B,WAAA,EAAa,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EACjC,QAAA,EAAU,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AACvB,CAAC;;;AC/EM,SAAS,0BAA0B,KAAA,EAAkD;AACxF,EAAA,OACE,OAAO,KAAA,KAAU,QAAA,IACjB,KAAA,KAAU,IAAA,IACV,WAAA,IAAe,KAAA,IACf,OAAQ,KAAA,CAAkC,SAAA,KAAc,QAAA,IACvD,KAAA,CAAkC,UAAU,MAAA,GAAS,CAAA;AAE1D;;;ACDK,SAAS,qBAAqB,GAAA,EAAuC;AAE1E,EAAA,OAAO;AAAA,IACL,WAAA,EAAA,SAAA;AAAA,IACA,KAAA,EAAO,IAAA,CAAK,SAAA,CAAU,GAAG;AAAA,GAC3B;AACF;;;ACJO,SAAS,gCACd,OAAA,EACoB;AACpB,EAAA,IAAI,CAAC,OAAA,IAAW,CAAC,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA,EAAG;AACvC,IAAA,OAAO,MAAA;AAAA,EACT;AAGA,EAAA,KAAA,MAAW,OAAO,OAAA,EAAS;AACzB,IAAA,IAAI,CAAC,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAA,EAAU;AACnC,MAAA;AAAA,IACF;AAGA,IAAA,MAAM,YAAY,GAAA,CAAI,WAAA;AACtB,IAAA,IAAI,SAAA,KAAA,SAAA,kBAAmD,IAAI,KAAA,EAAO;AAChE,MAAA,IAAI;AAEF,QAAA,MAAM,MAAA,GAAS,OAAO,GAAA,CAAI,KAAA,KAAU,QAAA,GAAW,KAAK,KAAA,CAAM,GAAA,CAAI,KAAK,CAAA,GAAI,GAAA,CAAI,KAAA;AAG3E,QAAA,IAAI,yBAAA,CAA0B,MAAM,CAAA,EAAG;AACrC,UAAA,OAAO,MAAA,CAAO,aAAA;AAAA,QAChB;AAAA,MACF,CAAA,CAAA,MAAQ;AAEN,QAAA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT;;;ACzCO,SAAS,iBAAiB,KAAA,EAAyC;AACxE,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,WAAA,IAAe,KAAA,IACf,OAAQ,KAAA,CAAkC,SAAA,KAAc,QAAA;AAE5D;;;ACAO,SAAS,yBAAyB,GAAA,EAA8B;AACrE,EAAA,OAAO;AAAA,IACL,WAAA,EAAA,cAAA;AAAA,IACA,KAAA,EAAO,IAAA,CAAK,SAAA,CAAU,GAAG;AAAA,GAC3B;AACF","file":"index.js","sourcesContent":["\nexport enum DesignProjectCtxNamespace {\n // 项目相关上下文\n Project = 'project',\n}\n\nexport interface DesignProjectProjectCtx {\n projectId: string;\n /** 草稿版本号, 如果没有那么则传递 undefined */\n workspaceHash: string | undefined;\n}\n\nexport enum AgentConfigCtxNamespace {\n // Agent 配置相关上下文\n Config = 'agent-config',\n}\n\nexport interface AgentConfigCtx {\n /** 模型类型,对应 ModelType 枚举值 */\n modelType: number;\n}\n","import { z } from \"zod\";\nimport type { Message as BaseMessage } from \"@ag-ui/core\";\n\n/**\n * Assistant message content part: thinking (reasoning) block.\n */\nexport interface AssistantContentPartThinking {\n type: \"thinking\";\n text: string;\n}\n\n/**\n * Assistant message content part: main answer text.\n */\nexport interface AssistantContentPartAnswer {\n type: \"answer\";\n text: string;\n}\n\n/**\n * Assistant message content part: inspire questions.\n */\nexport interface AssistantContentPartInspireQuestions {\n type: \"inspire_questions\";\n questions: string[];\n}\n\n/**\n * Assistant message content part: ask to continue prompt.\n */\nexport interface AssistantContentPartAskToContinue {\n type: \"ask_to_continue\";\n text: string;\n}\n\n/**\n * Discriminated union of all assistant content part types.\n */\nexport type AssistantContentPart =\n | AssistantContentPartThinking\n | AssistantContentPartAnswer\n | AssistantContentPartInspireQuestions\n | AssistantContentPartAskToContinue;\n\n/**\n * Assistant message content: either plain string (legacy/compat) or structured parts.\n * When string, treat as normal LLM response.\n */\nexport type AssistantMessageContent = string | AssistantContentPart[];\n\n/**\n * Type guard: content is array of parts (not plain string).\n */\nexport function isAssistantContentParts(\n content: AssistantMessageContent\n): content is AssistantContentPart[] {\n return Array.isArray(content);\n}\n\n/**\n * Message with extended assistant content (string | AssistantContentPart[]).\n * Other roles keep content as string; assistant may use AssistantMessageContent.\n */\nexport type Message =\n | (BaseMessage & { role: \"assistant\"; content: AssistantMessageContent })\n | (BaseMessage & { role?: \"user\" | \"tool\" | \"system\" });\n\n/**\n * Type guard: message is assistant with content parts.\n */\nexport function isAssistantMessageWithParts(\n msg: Message\n): msg is BaseMessage & { role: \"assistant\"; content: AssistantContentPart[] } {\n return msg.role === \"assistant\" && Array.isArray(msg.content);\n}\n\n/**\n * Metadata for assistant messages (business fields only).\n * Content semantics (thinking, inspire_questions, etc.) live in message.content as AssistantContentPart[].\n */\nexport const AssistantMessageMetadataSchema = z.object({\n runId: z.string().optional(),\n parentRunId: z.string().optional(),\n traceUrl: z.string().optional(),\n});\n\nexport type AssistantMessageMetadata = z.infer<typeof AssistantMessageMetadataSchema>;\n","/**\n * Type guard to check if an object matches DesignProjectProjectCtx\n */\nimport { type DesignProjectProjectCtx } from '../protocol';\n\nexport function isDesignProjectProjectCtx(value: unknown): value is DesignProjectProjectCtx {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'projectId' in value &&\n typeof (value as Record<string, unknown>).projectId === 'string' &&\n (value as DesignProjectProjectCtx).projectId.length > 0\n );\n }\n ","/**\n * Create project context for AG-UI RunAgentInput\n */\nimport { type DesignProjectProjectCtx, DesignProjectCtxNamespace } from '../protocol';\nimport type { Context } from '@ag-ui/core';\n\n/**\n * Create a project context item for AG-UI RunAgentInput\n *\n * @param projectId - The project ID\n * @returns Context item with namespace 'project' and projectId in value\n */\nexport function createProjectContext(ctx: DesignProjectProjectCtx): Context {\n // const projectCtx: DesignProjectProjectCtx = { projectId, workspaceHash };\n return {\n description: DesignProjectCtxNamespace.Project,\n value: JSON.stringify(ctx),\n };\n}\n","/**\n * Extract workspaceHash from context array\n * Looks for context with namespace 'project' and extracts workspaceHash from value\n */\nimport { type DesignProjectProjectCtx, DesignProjectCtxNamespace } from '../protocol';\nimport { isDesignProjectProjectCtx } from './is-project-ctx';\n\n/**\n * Extract workspaceHash from context array\n * Looks for context with namespace 'project' and extracts workspaceHash from value\n *\n * @param context - Context array from RunAgentInput\n * @returns workspaceHash if found, undefined otherwise\n */\nexport function extractWorkspaceHashFromContext(\n context: Array<{ description?: string; value?: string }> | undefined\n): string | undefined {\n if (!context || !Array.isArray(context)) {\n return undefined;\n }\n\n // Look for context with namespace 'project'\n for (const ctx of context) {\n if (!ctx || typeof ctx !== 'object') {\n continue;\n }\n\n // Check if this is a project context (namespace = 'project')\n const namespace = ctx.description;\n if (namespace === DesignProjectCtxNamespace.Project && ctx.value) {\n try {\n // Parse value as JSON (AG-UI Context.value is a string)\n const parsed = typeof ctx.value === 'string' ? JSON.parse(ctx.value) : ctx.value;\n\n // Use type guard to validate and extract workspaceHash with proper typing\n if (isDesignProjectProjectCtx(parsed)) {\n return parsed.workspaceHash;\n }\n } catch {\n // Invalid JSON, skip this context\n continue;\n }\n }\n }\n\n return undefined;\n}","/**\n * Type guard to check if an object matches AgentConfigCtx\n */\nimport { type AgentConfigCtx } from '../protocol';\n\nexport function isAgentConfigCtx(value: unknown): value is AgentConfigCtx {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'modelType' in value &&\n typeof (value as Record<string, unknown>).modelType === 'number'\n );\n}\n","/**\n * Create agent config context for AG-UI RunAgentInput\n */\nimport { type AgentConfigCtx, AgentConfigCtxNamespace } from '../protocol';\nimport type { Context } from '@ag-ui/core';\n\n/**\n * Create an agent config context item for AG-UI RunAgentInput\n *\n * @param ctx - The agent config context containing modelType\n * @returns Context item with namespace 'agent-config' and modelType in value\n */\nexport function createAgentConfigContext(ctx: AgentConfigCtx): Context {\n return {\n description: AgentConfigCtxNamespace.Config,\n value: JSON.stringify(ctx),\n };\n}\n"]}
@@ -1,11 +1,32 @@
1
1
  'use strict';
2
2
 
3
+ var zod = require('zod');
4
+
3
5
  // src/protocol/context.ts
4
6
  var DesignProjectCtxNamespace = /* @__PURE__ */ ((DesignProjectCtxNamespace2) => {
5
7
  DesignProjectCtxNamespace2["Project"] = "project";
6
8
  return DesignProjectCtxNamespace2;
7
9
  })(DesignProjectCtxNamespace || {});
10
+ var AgentConfigCtxNamespace = /* @__PURE__ */ ((AgentConfigCtxNamespace2) => {
11
+ AgentConfigCtxNamespace2["Config"] = "agent-config";
12
+ return AgentConfigCtxNamespace2;
13
+ })(AgentConfigCtxNamespace || {});
14
+ function isAssistantContentParts(content) {
15
+ return Array.isArray(content);
16
+ }
17
+ function isAssistantMessageWithParts(msg) {
18
+ return msg.role === "assistant" && Array.isArray(msg.content);
19
+ }
20
+ var AssistantMessageMetadataSchema = zod.z.object({
21
+ runId: zod.z.string().optional(),
22
+ parentRunId: zod.z.string().optional(),
23
+ traceUrl: zod.z.string().optional()
24
+ });
8
25
 
26
+ exports.AgentConfigCtxNamespace = AgentConfigCtxNamespace;
27
+ exports.AssistantMessageMetadataSchema = AssistantMessageMetadataSchema;
9
28
  exports.DesignProjectCtxNamespace = DesignProjectCtxNamespace;
29
+ exports.isAssistantContentParts = isAssistantContentParts;
30
+ exports.isAssistantMessageWithParts = isAssistantMessageWithParts;
10
31
  //# sourceMappingURL=index.cjs.map
11
32
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/protocol/context.ts"],"names":["DesignProjectCtxNamespace"],"mappings":";;;AACO,IAAK,yBAAA,qBAAAA,0BAAAA,KAAL;AAEH,EAAAA,2BAAA,SAAA,CAAA,GAAU,SAAA;AAFF,EAAA,OAAAA,0BAAAA;AAAA,CAAA,EAAA,yBAAA,IAAA,EAAA","file":"index.cjs","sourcesContent":["\nexport enum DesignProjectCtxNamespace {\n // 项目相关上下文\n Project = 'project',\n}\n\nexport interface DesignProjectProjectCtx {\n projectId: string;\n}"]}
1
+ {"version":3,"sources":["../../src/protocol/context.ts","../../src/protocol/message.ts"],"names":["DesignProjectCtxNamespace","AgentConfigCtxNamespace","z"],"mappings":";;;;;AACO,IAAK,yBAAA,qBAAAA,0BAAAA,KAAL;AAEH,EAAAA,2BAAA,SAAA,CAAA,GAAU,SAAA;AAFF,EAAA,OAAAA,0BAAAA;AAAA,CAAA,EAAA,yBAAA,IAAA,EAAA;AAWL,IAAK,uBAAA,qBAAAC,wBAAAA,KAAL;AAEH,EAAAA,yBAAA,QAAA,CAAA,GAAS,cAAA;AAFD,EAAA,OAAAA,wBAAAA;AAAA,CAAA,EAAA,uBAAA,IAAA,EAAA;ACyCL,SAAS,wBACd,OAAA,EACmC;AACnC,EAAA,OAAO,KAAA,CAAM,QAAQ,OAAO,CAAA;AAC9B;AAaO,SAAS,4BACd,GAAA,EAC6E;AAC7E,EAAA,OAAO,IAAI,IAAA,KAAS,WAAA,IAAe,KAAA,CAAM,OAAA,CAAQ,IAAI,OAAO,CAAA;AAC9D;AAMO,IAAM,8BAAA,GAAiCC,MAAE,MAAA,CAAO;AAAA,EACrD,KAAA,EAAOA,KAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC3B,WAAA,EAAaA,KAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EACjC,QAAA,EAAUA,KAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AACvB,CAAC","file":"index.cjs","sourcesContent":["\nexport enum DesignProjectCtxNamespace {\n // 项目相关上下文\n Project = 'project',\n}\n\nexport interface DesignProjectProjectCtx {\n projectId: string;\n /** 草稿版本号, 如果没有那么则传递 undefined */\n workspaceHash: string | undefined;\n}\n\nexport enum AgentConfigCtxNamespace {\n // Agent 配置相关上下文\n Config = 'agent-config',\n}\n\nexport interface AgentConfigCtx {\n /** 模型类型,对应 ModelType 枚举值 */\n modelType: number;\n}\n","import { z } from \"zod\";\nimport type { Message as BaseMessage } from \"@ag-ui/core\";\n\n/**\n * Assistant message content part: thinking (reasoning) block.\n */\nexport interface AssistantContentPartThinking {\n type: \"thinking\";\n text: string;\n}\n\n/**\n * Assistant message content part: main answer text.\n */\nexport interface AssistantContentPartAnswer {\n type: \"answer\";\n text: string;\n}\n\n/**\n * Assistant message content part: inspire questions.\n */\nexport interface AssistantContentPartInspireQuestions {\n type: \"inspire_questions\";\n questions: string[];\n}\n\n/**\n * Assistant message content part: ask to continue prompt.\n */\nexport interface AssistantContentPartAskToContinue {\n type: \"ask_to_continue\";\n text: string;\n}\n\n/**\n * Discriminated union of all assistant content part types.\n */\nexport type AssistantContentPart =\n | AssistantContentPartThinking\n | AssistantContentPartAnswer\n | AssistantContentPartInspireQuestions\n | AssistantContentPartAskToContinue;\n\n/**\n * Assistant message content: either plain string (legacy/compat) or structured parts.\n * When string, treat as normal LLM response.\n */\nexport type AssistantMessageContent = string | AssistantContentPart[];\n\n/**\n * Type guard: content is array of parts (not plain string).\n */\nexport function isAssistantContentParts(\n content: AssistantMessageContent\n): content is AssistantContentPart[] {\n return Array.isArray(content);\n}\n\n/**\n * Message with extended assistant content (string | AssistantContentPart[]).\n * Other roles keep content as string; assistant may use AssistantMessageContent.\n */\nexport type Message =\n | (BaseMessage & { role: \"assistant\"; content: AssistantMessageContent })\n | (BaseMessage & { role?: \"user\" | \"tool\" | \"system\" });\n\n/**\n * Type guard: message is assistant with content parts.\n */\nexport function isAssistantMessageWithParts(\n msg: Message\n): msg is BaseMessage & { role: \"assistant\"; content: AssistantContentPart[] } {\n return msg.role === \"assistant\" && Array.isArray(msg.content);\n}\n\n/**\n * Metadata for assistant messages (business fields only).\n * Content semantics (thinking, inspire_questions, etc.) live in message.content as AssistantContentPart[].\n */\nexport const AssistantMessageMetadataSchema = z.object({\n runId: z.string().optional(),\n parentRunId: z.string().optional(),\n traceUrl: z.string().optional(),\n});\n\nexport type AssistantMessageMetadata = z.infer<typeof AssistantMessageMetadataSchema>;\n"]}
@@ -1,8 +1,114 @@
1
- declare enum DesignProjectCtxNamespace {
2
- Project = "project"
1
+ export { b as AgentConfigCtx, A as AgentConfigCtxNamespace, D as DesignProjectCtxNamespace, a as DesignProjectProjectCtx } from '../context-CRBz7KR8.cjs';
2
+ import { z } from 'zod';
3
+ import { Message as Message$1, RunAgentInput as RunAgentInput$1 } from '@ag-ui/core';
4
+
5
+ /**
6
+ * Assistant message content part: thinking (reasoning) block.
7
+ */
8
+ interface AssistantContentPartThinking {
9
+ type: "thinking";
10
+ text: string;
11
+ }
12
+ /**
13
+ * Assistant message content part: main answer text.
14
+ */
15
+ interface AssistantContentPartAnswer {
16
+ type: "answer";
17
+ text: string;
18
+ }
19
+ /**
20
+ * Assistant message content part: inspire questions.
21
+ */
22
+ interface AssistantContentPartInspireQuestions {
23
+ type: "inspire_questions";
24
+ questions: string[];
25
+ }
26
+ /**
27
+ * Assistant message content part: ask to continue prompt.
28
+ */
29
+ interface AssistantContentPartAskToContinue {
30
+ type: "ask_to_continue";
31
+ text: string;
32
+ }
33
+ /**
34
+ * Discriminated union of all assistant content part types.
35
+ */
36
+ type AssistantContentPart = AssistantContentPartThinking | AssistantContentPartAnswer | AssistantContentPartInspireQuestions | AssistantContentPartAskToContinue;
37
+ /**
38
+ * Assistant message content: either plain string (legacy/compat) or structured parts.
39
+ * When string, treat as normal LLM response.
40
+ */
41
+ type AssistantMessageContent = string | AssistantContentPart[];
42
+ /**
43
+ * Type guard: content is array of parts (not plain string).
44
+ */
45
+ declare function isAssistantContentParts(content: AssistantMessageContent): content is AssistantContentPart[];
46
+ /**
47
+ * Message with extended assistant content (string | AssistantContentPart[]).
48
+ * Other roles keep content as string; assistant may use AssistantMessageContent.
49
+ */
50
+ type Message = (Message$1 & {
51
+ role: "assistant";
52
+ content: AssistantMessageContent;
53
+ }) | (Message$1 & {
54
+ role?: "user" | "tool" | "system";
55
+ });
56
+ /**
57
+ * Type guard: message is assistant with content parts.
58
+ */
59
+ declare function isAssistantMessageWithParts(msg: Message): msg is Message$1 & {
60
+ role: "assistant";
61
+ content: AssistantContentPart[];
62
+ };
63
+ /**
64
+ * Metadata for assistant messages (business fields only).
65
+ * Content semantics (thinking, inspire_questions, etc.) live in message.content as AssistantContentPart[].
66
+ */
67
+ declare const AssistantMessageMetadataSchema: z.ZodObject<{
68
+ runId: z.ZodOptional<z.ZodString>;
69
+ parentRunId: z.ZodOptional<z.ZodString>;
70
+ traceUrl: z.ZodOptional<z.ZodString>;
71
+ }, "strip", z.ZodTypeAny, {
72
+ runId?: string | undefined;
73
+ parentRunId?: string | undefined;
74
+ traceUrl?: string | undefined;
75
+ }, {
76
+ runId?: string | undefined;
77
+ parentRunId?: string | undefined;
78
+ traceUrl?: string | undefined;
79
+ }>;
80
+ type AssistantMessageMetadata = z.infer<typeof AssistantMessageMetadataSchema>;
81
+
82
+ /**
83
+ * RunAgentInput 类型重定义
84
+ * 直接使用 @ag-ui/core 的标准类型,保持协议一致性
85
+ */
86
+
87
+ /**
88
+ * Resume 选项类型(用于恢复中断的运行)
89
+ */
90
+ interface ResumeOption {
91
+ /**
92
+ * 中断 ID(可选,如果提供了则回显)
93
+ * 来自 RUN_FINISHED 事件中的 interrupt.id
94
+ */
95
+ interruptId?: string;
96
+ /**
97
+ * 用户响应数据(任意 JSON)
98
+ * 可以包含 approvals、edits、files-as-refs 等
99
+ */
100
+ payload?: any;
3
101
  }
4
- interface DesignProjectProjectCtx {
5
- projectId: string;
102
+ /**
103
+ * RunAgentInput 类型重定义
104
+ * 基于 @ag-ui/core 的标准类型,扩展 resume 字段以支持中断恢复
105
+ */
106
+ interface RunAgentInput extends RunAgentInput$1 {
107
+ /**
108
+ * Resume 选项(用于恢复中断的运行)
109
+ * 当需要恢复一个被中断的 run 时,提供此字段
110
+ */
111
+ resume?: ResumeOption;
6
112
  }
7
113
 
8
- export { DesignProjectCtxNamespace, type DesignProjectProjectCtx };
114
+ export { type AssistantContentPart, type AssistantContentPartAnswer, type AssistantContentPartAskToContinue, type AssistantContentPartInspireQuestions, type AssistantContentPartThinking, type AssistantMessageContent, type AssistantMessageMetadata, AssistantMessageMetadataSchema, type Message, type ResumeOption, type RunAgentInput, isAssistantContentParts, isAssistantMessageWithParts };
@@ -1,8 +1,114 @@
1
- declare enum DesignProjectCtxNamespace {
2
- Project = "project"
1
+ export { b as AgentConfigCtx, A as AgentConfigCtxNamespace, D as DesignProjectCtxNamespace, a as DesignProjectProjectCtx } from '../context-CRBz7KR8.js';
2
+ import { z } from 'zod';
3
+ import { Message as Message$1, RunAgentInput as RunAgentInput$1 } from '@ag-ui/core';
4
+
5
+ /**
6
+ * Assistant message content part: thinking (reasoning) block.
7
+ */
8
+ interface AssistantContentPartThinking {
9
+ type: "thinking";
10
+ text: string;
11
+ }
12
+ /**
13
+ * Assistant message content part: main answer text.
14
+ */
15
+ interface AssistantContentPartAnswer {
16
+ type: "answer";
17
+ text: string;
18
+ }
19
+ /**
20
+ * Assistant message content part: inspire questions.
21
+ */
22
+ interface AssistantContentPartInspireQuestions {
23
+ type: "inspire_questions";
24
+ questions: string[];
25
+ }
26
+ /**
27
+ * Assistant message content part: ask to continue prompt.
28
+ */
29
+ interface AssistantContentPartAskToContinue {
30
+ type: "ask_to_continue";
31
+ text: string;
32
+ }
33
+ /**
34
+ * Discriminated union of all assistant content part types.
35
+ */
36
+ type AssistantContentPart = AssistantContentPartThinking | AssistantContentPartAnswer | AssistantContentPartInspireQuestions | AssistantContentPartAskToContinue;
37
+ /**
38
+ * Assistant message content: either plain string (legacy/compat) or structured parts.
39
+ * When string, treat as normal LLM response.
40
+ */
41
+ type AssistantMessageContent = string | AssistantContentPart[];
42
+ /**
43
+ * Type guard: content is array of parts (not plain string).
44
+ */
45
+ declare function isAssistantContentParts(content: AssistantMessageContent): content is AssistantContentPart[];
46
+ /**
47
+ * Message with extended assistant content (string | AssistantContentPart[]).
48
+ * Other roles keep content as string; assistant may use AssistantMessageContent.
49
+ */
50
+ type Message = (Message$1 & {
51
+ role: "assistant";
52
+ content: AssistantMessageContent;
53
+ }) | (Message$1 & {
54
+ role?: "user" | "tool" | "system";
55
+ });
56
+ /**
57
+ * Type guard: message is assistant with content parts.
58
+ */
59
+ declare function isAssistantMessageWithParts(msg: Message): msg is Message$1 & {
60
+ role: "assistant";
61
+ content: AssistantContentPart[];
62
+ };
63
+ /**
64
+ * Metadata for assistant messages (business fields only).
65
+ * Content semantics (thinking, inspire_questions, etc.) live in message.content as AssistantContentPart[].
66
+ */
67
+ declare const AssistantMessageMetadataSchema: z.ZodObject<{
68
+ runId: z.ZodOptional<z.ZodString>;
69
+ parentRunId: z.ZodOptional<z.ZodString>;
70
+ traceUrl: z.ZodOptional<z.ZodString>;
71
+ }, "strip", z.ZodTypeAny, {
72
+ runId?: string | undefined;
73
+ parentRunId?: string | undefined;
74
+ traceUrl?: string | undefined;
75
+ }, {
76
+ runId?: string | undefined;
77
+ parentRunId?: string | undefined;
78
+ traceUrl?: string | undefined;
79
+ }>;
80
+ type AssistantMessageMetadata = z.infer<typeof AssistantMessageMetadataSchema>;
81
+
82
+ /**
83
+ * RunAgentInput 类型重定义
84
+ * 直接使用 @ag-ui/core 的标准类型,保持协议一致性
85
+ */
86
+
87
+ /**
88
+ * Resume 选项类型(用于恢复中断的运行)
89
+ */
90
+ interface ResumeOption {
91
+ /**
92
+ * 中断 ID(可选,如果提供了则回显)
93
+ * 来自 RUN_FINISHED 事件中的 interrupt.id
94
+ */
95
+ interruptId?: string;
96
+ /**
97
+ * 用户响应数据(任意 JSON)
98
+ * 可以包含 approvals、edits、files-as-refs 等
99
+ */
100
+ payload?: any;
3
101
  }
4
- interface DesignProjectProjectCtx {
5
- projectId: string;
102
+ /**
103
+ * RunAgentInput 类型重定义
104
+ * 基于 @ag-ui/core 的标准类型,扩展 resume 字段以支持中断恢复
105
+ */
106
+ interface RunAgentInput extends RunAgentInput$1 {
107
+ /**
108
+ * Resume 选项(用于恢复中断的运行)
109
+ * 当需要恢复一个被中断的 run 时,提供此字段
110
+ */
111
+ resume?: ResumeOption;
6
112
  }
7
113
 
8
- export { DesignProjectCtxNamespace, type DesignProjectProjectCtx };
114
+ export { type AssistantContentPart, type AssistantContentPartAnswer, type AssistantContentPartAskToContinue, type AssistantContentPartInspireQuestions, type AssistantContentPartThinking, type AssistantMessageContent, type AssistantMessageMetadata, AssistantMessageMetadataSchema, type Message, type ResumeOption, type RunAgentInput, isAssistantContentParts, isAssistantMessageWithParts };
@@ -1,9 +1,26 @@
1
+ import { z } from 'zod';
2
+
1
3
  // src/protocol/context.ts
2
4
  var DesignProjectCtxNamespace = /* @__PURE__ */ ((DesignProjectCtxNamespace2) => {
3
5
  DesignProjectCtxNamespace2["Project"] = "project";
4
6
  return DesignProjectCtxNamespace2;
5
7
  })(DesignProjectCtxNamespace || {});
8
+ var AgentConfigCtxNamespace = /* @__PURE__ */ ((AgentConfigCtxNamespace2) => {
9
+ AgentConfigCtxNamespace2["Config"] = "agent-config";
10
+ return AgentConfigCtxNamespace2;
11
+ })(AgentConfigCtxNamespace || {});
12
+ function isAssistantContentParts(content) {
13
+ return Array.isArray(content);
14
+ }
15
+ function isAssistantMessageWithParts(msg) {
16
+ return msg.role === "assistant" && Array.isArray(msg.content);
17
+ }
18
+ var AssistantMessageMetadataSchema = z.object({
19
+ runId: z.string().optional(),
20
+ parentRunId: z.string().optional(),
21
+ traceUrl: z.string().optional()
22
+ });
6
23
 
7
- export { DesignProjectCtxNamespace };
24
+ export { AgentConfigCtxNamespace, AssistantMessageMetadataSchema, DesignProjectCtxNamespace, isAssistantContentParts, isAssistantMessageWithParts };
8
25
  //# sourceMappingURL=index.js.map
9
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/protocol/context.ts"],"names":["DesignProjectCtxNamespace"],"mappings":";AACO,IAAK,yBAAA,qBAAAA,0BAAAA,KAAL;AAEH,EAAAA,2BAAA,SAAA,CAAA,GAAU,SAAA;AAFF,EAAA,OAAAA,0BAAAA;AAAA,CAAA,EAAA,yBAAA,IAAA,EAAA","file":"index.js","sourcesContent":["\nexport enum DesignProjectCtxNamespace {\n // 项目相关上下文\n Project = 'project',\n}\n\nexport interface DesignProjectProjectCtx {\n projectId: string;\n}"]}
1
+ {"version":3,"sources":["../../src/protocol/context.ts","../../src/protocol/message.ts"],"names":["DesignProjectCtxNamespace","AgentConfigCtxNamespace"],"mappings":";;;AACO,IAAK,yBAAA,qBAAAA,0BAAAA,KAAL;AAEH,EAAAA,2BAAA,SAAA,CAAA,GAAU,SAAA;AAFF,EAAA,OAAAA,0BAAAA;AAAA,CAAA,EAAA,yBAAA,IAAA,EAAA;AAWL,IAAK,uBAAA,qBAAAC,wBAAAA,KAAL;AAEH,EAAAA,yBAAA,QAAA,CAAA,GAAS,cAAA;AAFD,EAAA,OAAAA,wBAAAA;AAAA,CAAA,EAAA,uBAAA,IAAA,EAAA;ACyCL,SAAS,wBACd,OAAA,EACmC;AACnC,EAAA,OAAO,KAAA,CAAM,QAAQ,OAAO,CAAA;AAC9B;AAaO,SAAS,4BACd,GAAA,EAC6E;AAC7E,EAAA,OAAO,IAAI,IAAA,KAAS,WAAA,IAAe,KAAA,CAAM,OAAA,CAAQ,IAAI,OAAO,CAAA;AAC9D;AAMO,IAAM,8BAAA,GAAiC,EAAE,MAAA,CAAO;AAAA,EACrD,KAAA,EAAO,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC3B,WAAA,EAAa,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EACjC,QAAA,EAAU,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AACvB,CAAC","file":"index.js","sourcesContent":["\nexport enum DesignProjectCtxNamespace {\n // 项目相关上下文\n Project = 'project',\n}\n\nexport interface DesignProjectProjectCtx {\n projectId: string;\n /** 草稿版本号, 如果没有那么则传递 undefined */\n workspaceHash: string | undefined;\n}\n\nexport enum AgentConfigCtxNamespace {\n // Agent 配置相关上下文\n Config = 'agent-config',\n}\n\nexport interface AgentConfigCtx {\n /** 模型类型,对应 ModelType 枚举值 */\n modelType: number;\n}\n","import { z } from \"zod\";\nimport type { Message as BaseMessage } from \"@ag-ui/core\";\n\n/**\n * Assistant message content part: thinking (reasoning) block.\n */\nexport interface AssistantContentPartThinking {\n type: \"thinking\";\n text: string;\n}\n\n/**\n * Assistant message content part: main answer text.\n */\nexport interface AssistantContentPartAnswer {\n type: \"answer\";\n text: string;\n}\n\n/**\n * Assistant message content part: inspire questions.\n */\nexport interface AssistantContentPartInspireQuestions {\n type: \"inspire_questions\";\n questions: string[];\n}\n\n/**\n * Assistant message content part: ask to continue prompt.\n */\nexport interface AssistantContentPartAskToContinue {\n type: \"ask_to_continue\";\n text: string;\n}\n\n/**\n * Discriminated union of all assistant content part types.\n */\nexport type AssistantContentPart =\n | AssistantContentPartThinking\n | AssistantContentPartAnswer\n | AssistantContentPartInspireQuestions\n | AssistantContentPartAskToContinue;\n\n/**\n * Assistant message content: either plain string (legacy/compat) or structured parts.\n * When string, treat as normal LLM response.\n */\nexport type AssistantMessageContent = string | AssistantContentPart[];\n\n/**\n * Type guard: content is array of parts (not plain string).\n */\nexport function isAssistantContentParts(\n content: AssistantMessageContent\n): content is AssistantContentPart[] {\n return Array.isArray(content);\n}\n\n/**\n * Message with extended assistant content (string | AssistantContentPart[]).\n * Other roles keep content as string; assistant may use AssistantMessageContent.\n */\nexport type Message =\n | (BaseMessage & { role: \"assistant\"; content: AssistantMessageContent })\n | (BaseMessage & { role?: \"user\" | \"tool\" | \"system\" });\n\n/**\n * Type guard: message is assistant with content parts.\n */\nexport function isAssistantMessageWithParts(\n msg: Message\n): msg is BaseMessage & { role: \"assistant\"; content: AssistantContentPart[] } {\n return msg.role === \"assistant\" && Array.isArray(msg.content);\n}\n\n/**\n * Metadata for assistant messages (business fields only).\n * Content semantics (thinking, inspire_questions, etc.) live in message.content as AssistantContentPart[].\n */\nexport const AssistantMessageMetadataSchema = z.object({\n runId: z.string().optional(),\n parentRunId: z.string().optional(),\n traceUrl: z.string().optional(),\n});\n\nexport type AssistantMessageMetadata = z.infer<typeof AssistantMessageMetadataSchema>;\n"]}
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ // src/utils/is-project-ctx.ts
4
+ function isDesignProjectProjectCtx(value) {
5
+ return typeof value === "object" && value !== null && "projectId" in value && typeof value.projectId === "string" && value.projectId.length > 0;
6
+ }
7
+
8
+ // src/utils/create-project-context.ts
9
+ function createProjectContext(ctx) {
10
+ return {
11
+ description: "project" /* Project */,
12
+ value: JSON.stringify(ctx)
13
+ };
14
+ }
15
+
16
+ // src/utils/extract-workspace-hash-from-context.ts
17
+ function extractWorkspaceHashFromContext(context) {
18
+ if (!context || !Array.isArray(context)) {
19
+ return void 0;
20
+ }
21
+ for (const ctx of context) {
22
+ if (!ctx || typeof ctx !== "object") {
23
+ continue;
24
+ }
25
+ const namespace = ctx.description;
26
+ if (namespace === "project" /* Project */ && ctx.value) {
27
+ try {
28
+ const parsed = typeof ctx.value === "string" ? JSON.parse(ctx.value) : ctx.value;
29
+ if (isDesignProjectProjectCtx(parsed)) {
30
+ return parsed.workspaceHash;
31
+ }
32
+ } catch {
33
+ continue;
34
+ }
35
+ }
36
+ }
37
+ return void 0;
38
+ }
39
+
40
+ // src/utils/is-agent-config-ctx.ts
41
+ function isAgentConfigCtx(value) {
42
+ return typeof value === "object" && value !== null && "modelType" in value && typeof value.modelType === "number";
43
+ }
44
+
45
+ // src/utils/create-agent-config-context.ts
46
+ function createAgentConfigContext(ctx) {
47
+ return {
48
+ description: "agent-config" /* Config */,
49
+ value: JSON.stringify(ctx)
50
+ };
51
+ }
52
+
53
+ exports.createAgentConfigContext = createAgentConfigContext;
54
+ exports.createProjectContext = createProjectContext;
55
+ exports.extractWorkspaceHashFromContext = extractWorkspaceHashFromContext;
56
+ exports.isAgentConfigCtx = isAgentConfigCtx;
57
+ exports.isDesignProjectProjectCtx = isDesignProjectProjectCtx;
58
+ //# sourceMappingURL=index.cjs.map
59
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/is-project-ctx.ts","../../src/utils/create-project-context.ts","../../src/utils/extract-workspace-hash-from-context.ts","../../src/utils/is-agent-config-ctx.ts","../../src/utils/create-agent-config-context.ts"],"names":[],"mappings":";;;AAKO,SAAS,0BAA0B,KAAA,EAAkD;AACxF,EAAA,OACE,OAAO,KAAA,KAAU,QAAA,IACjB,KAAA,KAAU,IAAA,IACV,WAAA,IAAe,KAAA,IACf,OAAQ,KAAA,CAAkC,SAAA,KAAc,QAAA,IACvD,KAAA,CAAkC,UAAU,MAAA,GAAS,CAAA;AAE1D;;;ACDK,SAAS,qBAAqB,GAAA,EAAuC;AAE1E,EAAA,OAAO;AAAA,IACL,WAAA,EAAA,SAAA;AAAA,IACA,KAAA,EAAO,IAAA,CAAK,SAAA,CAAU,GAAG;AAAA,GAC3B;AACF;;;ACJO,SAAS,gCACd,OAAA,EACoB;AACpB,EAAA,IAAI,CAAC,OAAA,IAAW,CAAC,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA,EAAG;AACvC,IAAA,OAAO,MAAA;AAAA,EACT;AAGA,EAAA,KAAA,MAAW,OAAO,OAAA,EAAS;AACzB,IAAA,IAAI,CAAC,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAA,EAAU;AACnC,MAAA;AAAA,IACF;AAGA,IAAA,MAAM,YAAY,GAAA,CAAI,WAAA;AACtB,IAAA,IAAI,SAAA,KAAA,SAAA,kBAAmD,IAAI,KAAA,EAAO;AAChE,MAAA,IAAI;AAEF,QAAA,MAAM,MAAA,GAAS,OAAO,GAAA,CAAI,KAAA,KAAU,QAAA,GAAW,KAAK,KAAA,CAAM,GAAA,CAAI,KAAK,CAAA,GAAI,GAAA,CAAI,KAAA;AAG3E,QAAA,IAAI,yBAAA,CAA0B,MAAM,CAAA,EAAG;AACrC,UAAA,OAAO,MAAA,CAAO,aAAA;AAAA,QAChB;AAAA,MACF,CAAA,CAAA,MAAQ;AAEN,QAAA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT;;;ACzCO,SAAS,iBAAiB,KAAA,EAAyC;AACxE,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,WAAA,IAAe,KAAA,IACf,OAAQ,KAAA,CAAkC,SAAA,KAAc,QAAA;AAE5D;;;ACAO,SAAS,yBAAyB,GAAA,EAA8B;AACrE,EAAA,OAAO;AAAA,IACL,WAAA,EAAA,cAAA;AAAA,IACA,KAAA,EAAO,IAAA,CAAK,SAAA,CAAU,GAAG;AAAA,GAC3B;AACF","file":"index.cjs","sourcesContent":["/**\n * Type guard to check if an object matches DesignProjectProjectCtx\n */\nimport { type DesignProjectProjectCtx } from '../protocol';\n\nexport function isDesignProjectProjectCtx(value: unknown): value is DesignProjectProjectCtx {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'projectId' in value &&\n typeof (value as Record<string, unknown>).projectId === 'string' &&\n (value as DesignProjectProjectCtx).projectId.length > 0\n );\n }\n ","/**\n * Create project context for AG-UI RunAgentInput\n */\nimport { type DesignProjectProjectCtx, DesignProjectCtxNamespace } from '../protocol';\nimport type { Context } from '@ag-ui/core';\n\n/**\n * Create a project context item for AG-UI RunAgentInput\n *\n * @param projectId - The project ID\n * @returns Context item with namespace 'project' and projectId in value\n */\nexport function createProjectContext(ctx: DesignProjectProjectCtx): Context {\n // const projectCtx: DesignProjectProjectCtx = { projectId, workspaceHash };\n return {\n description: DesignProjectCtxNamespace.Project,\n value: JSON.stringify(ctx),\n };\n}\n","/**\n * Extract workspaceHash from context array\n * Looks for context with namespace 'project' and extracts workspaceHash from value\n */\nimport { type DesignProjectProjectCtx, DesignProjectCtxNamespace } from '../protocol';\nimport { isDesignProjectProjectCtx } from './is-project-ctx';\n\n/**\n * Extract workspaceHash from context array\n * Looks for context with namespace 'project' and extracts workspaceHash from value\n *\n * @param context - Context array from RunAgentInput\n * @returns workspaceHash if found, undefined otherwise\n */\nexport function extractWorkspaceHashFromContext(\n context: Array<{ description?: string; value?: string }> | undefined\n): string | undefined {\n if (!context || !Array.isArray(context)) {\n return undefined;\n }\n\n // Look for context with namespace 'project'\n for (const ctx of context) {\n if (!ctx || typeof ctx !== 'object') {\n continue;\n }\n\n // Check if this is a project context (namespace = 'project')\n const namespace = ctx.description;\n if (namespace === DesignProjectCtxNamespace.Project && ctx.value) {\n try {\n // Parse value as JSON (AG-UI Context.value is a string)\n const parsed = typeof ctx.value === 'string' ? JSON.parse(ctx.value) : ctx.value;\n\n // Use type guard to validate and extract workspaceHash with proper typing\n if (isDesignProjectProjectCtx(parsed)) {\n return parsed.workspaceHash;\n }\n } catch {\n // Invalid JSON, skip this context\n continue;\n }\n }\n }\n\n return undefined;\n}","/**\n * Type guard to check if an object matches AgentConfigCtx\n */\nimport { type AgentConfigCtx } from '../protocol';\n\nexport function isAgentConfigCtx(value: unknown): value is AgentConfigCtx {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'modelType' in value &&\n typeof (value as Record<string, unknown>).modelType === 'number'\n );\n}\n","/**\n * Create agent config context for AG-UI RunAgentInput\n */\nimport { type AgentConfigCtx, AgentConfigCtxNamespace } from '../protocol';\nimport type { Context } from '@ag-ui/core';\n\n/**\n * Create an agent config context item for AG-UI RunAgentInput\n *\n * @param ctx - The agent config context containing modelType\n * @returns Context item with namespace 'agent-config' and modelType in value\n */\nexport function createAgentConfigContext(ctx: AgentConfigCtx): Context {\n return {\n description: AgentConfigCtxNamespace.Config,\n value: JSON.stringify(ctx),\n };\n}\n"]}
@@ -0,0 +1,52 @@
1
+ import { a as DesignProjectProjectCtx, b as AgentConfigCtx } from '../context-CRBz7KR8.cjs';
2
+ import { Context } from '@ag-ui/core';
3
+
4
+ /**
5
+ * Type guard to check if an object matches DesignProjectProjectCtx
6
+ */
7
+
8
+ declare function isDesignProjectProjectCtx(value: unknown): value is DesignProjectProjectCtx;
9
+
10
+ /**
11
+ * Create project context for AG-UI RunAgentInput
12
+ */
13
+
14
+ /**
15
+ * Create a project context item for AG-UI RunAgentInput
16
+ *
17
+ * @param projectId - The project ID
18
+ * @returns Context item with namespace 'project' and projectId in value
19
+ */
20
+ declare function createProjectContext(ctx: DesignProjectProjectCtx): Context;
21
+
22
+ /**
23
+ * Extract workspaceHash from context array
24
+ * Looks for context with namespace 'project' and extracts workspaceHash from value
25
+ *
26
+ * @param context - Context array from RunAgentInput
27
+ * @returns workspaceHash if found, undefined otherwise
28
+ */
29
+ declare function extractWorkspaceHashFromContext(context: Array<{
30
+ description?: string;
31
+ value?: string;
32
+ }> | undefined): string | undefined;
33
+
34
+ /**
35
+ * Type guard to check if an object matches AgentConfigCtx
36
+ */
37
+
38
+ declare function isAgentConfigCtx(value: unknown): value is AgentConfigCtx;
39
+
40
+ /**
41
+ * Create agent config context for AG-UI RunAgentInput
42
+ */
43
+
44
+ /**
45
+ * Create an agent config context item for AG-UI RunAgentInput
46
+ *
47
+ * @param ctx - The agent config context containing modelType
48
+ * @returns Context item with namespace 'agent-config' and modelType in value
49
+ */
50
+ declare function createAgentConfigContext(ctx: AgentConfigCtx): Context;
51
+
52
+ export { createAgentConfigContext, createProjectContext, extractWorkspaceHashFromContext, isAgentConfigCtx, isDesignProjectProjectCtx };
@@ -0,0 +1,52 @@
1
+ import { a as DesignProjectProjectCtx, b as AgentConfigCtx } from '../context-CRBz7KR8.js';
2
+ import { Context } from '@ag-ui/core';
3
+
4
+ /**
5
+ * Type guard to check if an object matches DesignProjectProjectCtx
6
+ */
7
+
8
+ declare function isDesignProjectProjectCtx(value: unknown): value is DesignProjectProjectCtx;
9
+
10
+ /**
11
+ * Create project context for AG-UI RunAgentInput
12
+ */
13
+
14
+ /**
15
+ * Create a project context item for AG-UI RunAgentInput
16
+ *
17
+ * @param projectId - The project ID
18
+ * @returns Context item with namespace 'project' and projectId in value
19
+ */
20
+ declare function createProjectContext(ctx: DesignProjectProjectCtx): Context;
21
+
22
+ /**
23
+ * Extract workspaceHash from context array
24
+ * Looks for context with namespace 'project' and extracts workspaceHash from value
25
+ *
26
+ * @param context - Context array from RunAgentInput
27
+ * @returns workspaceHash if found, undefined otherwise
28
+ */
29
+ declare function extractWorkspaceHashFromContext(context: Array<{
30
+ description?: string;
31
+ value?: string;
32
+ }> | undefined): string | undefined;
33
+
34
+ /**
35
+ * Type guard to check if an object matches AgentConfigCtx
36
+ */
37
+
38
+ declare function isAgentConfigCtx(value: unknown): value is AgentConfigCtx;
39
+
40
+ /**
41
+ * Create agent config context for AG-UI RunAgentInput
42
+ */
43
+
44
+ /**
45
+ * Create an agent config context item for AG-UI RunAgentInput
46
+ *
47
+ * @param ctx - The agent config context containing modelType
48
+ * @returns Context item with namespace 'agent-config' and modelType in value
49
+ */
50
+ declare function createAgentConfigContext(ctx: AgentConfigCtx): Context;
51
+
52
+ export { createAgentConfigContext, createProjectContext, extractWorkspaceHashFromContext, isAgentConfigCtx, isDesignProjectProjectCtx };
@@ -0,0 +1,53 @@
1
+ // src/utils/is-project-ctx.ts
2
+ function isDesignProjectProjectCtx(value) {
3
+ return typeof value === "object" && value !== null && "projectId" in value && typeof value.projectId === "string" && value.projectId.length > 0;
4
+ }
5
+
6
+ // src/utils/create-project-context.ts
7
+ function createProjectContext(ctx) {
8
+ return {
9
+ description: "project" /* Project */,
10
+ value: JSON.stringify(ctx)
11
+ };
12
+ }
13
+
14
+ // src/utils/extract-workspace-hash-from-context.ts
15
+ function extractWorkspaceHashFromContext(context) {
16
+ if (!context || !Array.isArray(context)) {
17
+ return void 0;
18
+ }
19
+ for (const ctx of context) {
20
+ if (!ctx || typeof ctx !== "object") {
21
+ continue;
22
+ }
23
+ const namespace = ctx.description;
24
+ if (namespace === "project" /* Project */ && ctx.value) {
25
+ try {
26
+ const parsed = typeof ctx.value === "string" ? JSON.parse(ctx.value) : ctx.value;
27
+ if (isDesignProjectProjectCtx(parsed)) {
28
+ return parsed.workspaceHash;
29
+ }
30
+ } catch {
31
+ continue;
32
+ }
33
+ }
34
+ }
35
+ return void 0;
36
+ }
37
+
38
+ // src/utils/is-agent-config-ctx.ts
39
+ function isAgentConfigCtx(value) {
40
+ return typeof value === "object" && value !== null && "modelType" in value && typeof value.modelType === "number";
41
+ }
42
+
43
+ // src/utils/create-agent-config-context.ts
44
+ function createAgentConfigContext(ctx) {
45
+ return {
46
+ description: "agent-config" /* Config */,
47
+ value: JSON.stringify(ctx)
48
+ };
49
+ }
50
+
51
+ export { createAgentConfigContext, createProjectContext, extractWorkspaceHashFromContext, isAgentConfigCtx, isDesignProjectProjectCtx };
52
+ //# sourceMappingURL=index.js.map
53
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/is-project-ctx.ts","../../src/utils/create-project-context.ts","../../src/utils/extract-workspace-hash-from-context.ts","../../src/utils/is-agent-config-ctx.ts","../../src/utils/create-agent-config-context.ts"],"names":[],"mappings":";AAKO,SAAS,0BAA0B,KAAA,EAAkD;AACxF,EAAA,OACE,OAAO,KAAA,KAAU,QAAA,IACjB,KAAA,KAAU,IAAA,IACV,WAAA,IAAe,KAAA,IACf,OAAQ,KAAA,CAAkC,SAAA,KAAc,QAAA,IACvD,KAAA,CAAkC,UAAU,MAAA,GAAS,CAAA;AAE1D;;;ACDK,SAAS,qBAAqB,GAAA,EAAuC;AAE1E,EAAA,OAAO;AAAA,IACL,WAAA,EAAA,SAAA;AAAA,IACA,KAAA,EAAO,IAAA,CAAK,SAAA,CAAU,GAAG;AAAA,GAC3B;AACF;;;ACJO,SAAS,gCACd,OAAA,EACoB;AACpB,EAAA,IAAI,CAAC,OAAA,IAAW,CAAC,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA,EAAG;AACvC,IAAA,OAAO,MAAA;AAAA,EACT;AAGA,EAAA,KAAA,MAAW,OAAO,OAAA,EAAS;AACzB,IAAA,IAAI,CAAC,GAAA,IAAO,OAAO,GAAA,KAAQ,QAAA,EAAU;AACnC,MAAA;AAAA,IACF;AAGA,IAAA,MAAM,YAAY,GAAA,CAAI,WAAA;AACtB,IAAA,IAAI,SAAA,KAAA,SAAA,kBAAmD,IAAI,KAAA,EAAO;AAChE,MAAA,IAAI;AAEF,QAAA,MAAM,MAAA,GAAS,OAAO,GAAA,CAAI,KAAA,KAAU,QAAA,GAAW,KAAK,KAAA,CAAM,GAAA,CAAI,KAAK,CAAA,GAAI,GAAA,CAAI,KAAA;AAG3E,QAAA,IAAI,yBAAA,CAA0B,MAAM,CAAA,EAAG;AACrC,UAAA,OAAO,MAAA,CAAO,aAAA;AAAA,QAChB;AAAA,MACF,CAAA,CAAA,MAAQ;AAEN,QAAA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT;;;ACzCO,SAAS,iBAAiB,KAAA,EAAyC;AACxE,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,WAAA,IAAe,KAAA,IACf,OAAQ,KAAA,CAAkC,SAAA,KAAc,QAAA;AAE5D;;;ACAO,SAAS,yBAAyB,GAAA,EAA8B;AACrE,EAAA,OAAO;AAAA,IACL,WAAA,EAAA,cAAA;AAAA,IACA,KAAA,EAAO,IAAA,CAAK,SAAA,CAAU,GAAG;AAAA,GAC3B;AACF","file":"index.js","sourcesContent":["/**\n * Type guard to check if an object matches DesignProjectProjectCtx\n */\nimport { type DesignProjectProjectCtx } from '../protocol';\n\nexport function isDesignProjectProjectCtx(value: unknown): value is DesignProjectProjectCtx {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'projectId' in value &&\n typeof (value as Record<string, unknown>).projectId === 'string' &&\n (value as DesignProjectProjectCtx).projectId.length > 0\n );\n }\n ","/**\n * Create project context for AG-UI RunAgentInput\n */\nimport { type DesignProjectProjectCtx, DesignProjectCtxNamespace } from '../protocol';\nimport type { Context } from '@ag-ui/core';\n\n/**\n * Create a project context item for AG-UI RunAgentInput\n *\n * @param projectId - The project ID\n * @returns Context item with namespace 'project' and projectId in value\n */\nexport function createProjectContext(ctx: DesignProjectProjectCtx): Context {\n // const projectCtx: DesignProjectProjectCtx = { projectId, workspaceHash };\n return {\n description: DesignProjectCtxNamespace.Project,\n value: JSON.stringify(ctx),\n };\n}\n","/**\n * Extract workspaceHash from context array\n * Looks for context with namespace 'project' and extracts workspaceHash from value\n */\nimport { type DesignProjectProjectCtx, DesignProjectCtxNamespace } from '../protocol';\nimport { isDesignProjectProjectCtx } from './is-project-ctx';\n\n/**\n * Extract workspaceHash from context array\n * Looks for context with namespace 'project' and extracts workspaceHash from value\n *\n * @param context - Context array from RunAgentInput\n * @returns workspaceHash if found, undefined otherwise\n */\nexport function extractWorkspaceHashFromContext(\n context: Array<{ description?: string; value?: string }> | undefined\n): string | undefined {\n if (!context || !Array.isArray(context)) {\n return undefined;\n }\n\n // Look for context with namespace 'project'\n for (const ctx of context) {\n if (!ctx || typeof ctx !== 'object') {\n continue;\n }\n\n // Check if this is a project context (namespace = 'project')\n const namespace = ctx.description;\n if (namespace === DesignProjectCtxNamespace.Project && ctx.value) {\n try {\n // Parse value as JSON (AG-UI Context.value is a string)\n const parsed = typeof ctx.value === 'string' ? JSON.parse(ctx.value) : ctx.value;\n\n // Use type guard to validate and extract workspaceHash with proper typing\n if (isDesignProjectProjectCtx(parsed)) {\n return parsed.workspaceHash;\n }\n } catch {\n // Invalid JSON, skip this context\n continue;\n }\n }\n }\n\n return undefined;\n}","/**\n * Type guard to check if an object matches AgentConfigCtx\n */\nimport { type AgentConfigCtx } from '../protocol';\n\nexport function isAgentConfigCtx(value: unknown): value is AgentConfigCtx {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'modelType' in value &&\n typeof (value as Record<string, unknown>).modelType === 'number'\n );\n}\n","/**\n * Create agent config context for AG-UI RunAgentInput\n */\nimport { type AgentConfigCtx, AgentConfigCtxNamespace } from '../protocol';\nimport type { Context } from '@ag-ui/core';\n\n/**\n * Create an agent config context item for AG-UI RunAgentInput\n *\n * @param ctx - The agent config context containing modelType\n * @returns Context item with namespace 'agent-config' and modelType in value\n */\nexport function createAgentConfigContext(ctx: AgentConfigCtx): Context {\n return {\n description: AgentConfigCtxNamespace.Config,\n value: JSON.stringify(ctx),\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zk-tech/ag-ui-core",
3
- "version": "0.0.1-alpha.1",
3
+ "version": "0.0.1-alpha.10",
4
4
  "description": "Extends from AG-UI core with more strict types",
5
5
  "license": "MIT",
6
6
  "author": "ZK Tech",
@@ -25,6 +25,11 @@
25
25
  "types": "./dist/protocol/index.d.ts",
26
26
  "import": "./dist/protocol/index.js",
27
27
  "require": "./dist/protocol/index.cjs"
28
+ },
29
+ "./utils": {
30
+ "types": "./dist/utils/index.d.ts",
31
+ "import": "./dist/utils/index.js",
32
+ "require": "./dist/utils/index.cjs"
28
33
  }
29
34
  },
30
35
  "scripts": {
@@ -34,8 +39,11 @@
34
39
  "clean": "rm -rf dist",
35
40
  "prepublishOnly": "pnpm run build"
36
41
  },
37
- "devDependencies": {
42
+ "dependencies": {
38
43
  "@ag-ui/core": "^0.0.42",
44
+ "zod": "^3.25.0"
45
+ },
46
+ "devDependencies": {
39
47
  "tsup": "^8.5.1",
40
48
  "typescript": "^5.9.3"
41
49
  },