@zk-tech/ag-ui-core 0.0.1-alpha.5 → 0.0.1-alpha.6

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/index.cjs CHANGED
@@ -19,8 +19,33 @@ function createProjectContext(ctx) {
19
19
  };
20
20
  }
21
21
 
22
+ // src/utils/extract-workspace-hash-from-context.ts
23
+ function extractWorkspaceHashFromContext(context) {
24
+ if (!context || !Array.isArray(context)) {
25
+ return void 0;
26
+ }
27
+ for (const ctx of context) {
28
+ if (!ctx || typeof ctx !== "object") {
29
+ continue;
30
+ }
31
+ const namespace = ctx.description;
32
+ if (namespace === "project" /* Project */ && ctx.value) {
33
+ try {
34
+ const parsed = typeof ctx.value === "string" ? JSON.parse(ctx.value) : ctx.value;
35
+ if (isDesignProjectProjectCtx(parsed)) {
36
+ return parsed.workspaceHash;
37
+ }
38
+ } catch {
39
+ continue;
40
+ }
41
+ }
42
+ }
43
+ return void 0;
44
+ }
45
+
22
46
  exports.DesignProjectCtxNamespace = DesignProjectCtxNamespace;
23
47
  exports.createProjectContext = createProjectContext;
48
+ exports.extractWorkspaceHashFromContext = extractWorkspaceHashFromContext;
24
49
  exports.isDesignProjectProjectCtx = isDesignProjectProjectCtx;
25
50
  //# sourceMappingURL=index.cjs.map
26
51
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/protocol/context.ts","../src/utils/is-project-ctx.ts","../src/utils/create-project-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;;;ACIL,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","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 * 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"]}
1
+ {"version":3,"sources":["../src/protocol/context.ts","../src/utils/is-project-ctx.ts","../src/utils/create-project-context.ts","../src/utils/extract-workspace-hash-from-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;;;ACIL,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","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 * 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}"]}
package/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { DesignProjectCtxNamespace, DesignProjectProjectCtx } from './protocol/index.cjs';
2
- export { createProjectContext, isDesignProjectProjectCtx } from './utils/index.cjs';
2
+ export { createProjectContext, extractWorkspaceHashFromContext, isDesignProjectProjectCtx } from './utils/index.cjs';
3
3
  import '@ag-ui/core';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { DesignProjectCtxNamespace, DesignProjectProjectCtx } from './protocol/index.js';
2
- export { createProjectContext, isDesignProjectProjectCtx } from './utils/index.js';
2
+ export { createProjectContext, extractWorkspaceHashFromContext, isDesignProjectProjectCtx } from './utils/index.js';
3
3
  import '@ag-ui/core';
package/dist/index.js CHANGED
@@ -17,6 +17,30 @@ function createProjectContext(ctx) {
17
17
  };
18
18
  }
19
19
 
20
- export { DesignProjectCtxNamespace, createProjectContext, isDesignProjectProjectCtx };
20
+ // src/utils/extract-workspace-hash-from-context.ts
21
+ function extractWorkspaceHashFromContext(context) {
22
+ if (!context || !Array.isArray(context)) {
23
+ return void 0;
24
+ }
25
+ for (const ctx of context) {
26
+ if (!ctx || typeof ctx !== "object") {
27
+ continue;
28
+ }
29
+ const namespace = ctx.description;
30
+ if (namespace === "project" /* Project */ && ctx.value) {
31
+ try {
32
+ const parsed = typeof ctx.value === "string" ? JSON.parse(ctx.value) : ctx.value;
33
+ if (isDesignProjectProjectCtx(parsed)) {
34
+ return parsed.workspaceHash;
35
+ }
36
+ } catch {
37
+ continue;
38
+ }
39
+ }
40
+ }
41
+ return void 0;
42
+ }
43
+
44
+ export { DesignProjectCtxNamespace, createProjectContext, extractWorkspaceHashFromContext, isDesignProjectProjectCtx };
21
45
  //# sourceMappingURL=index.js.map
22
46
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/protocol/context.ts","../src/utils/is-project-ctx.ts","../src/utils/create-project-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;;;ACIL,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","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 * 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"]}
1
+ {"version":3,"sources":["../src/protocol/context.ts","../src/utils/is-project-ctx.ts","../src/utils/create-project-context.ts","../src/utils/extract-workspace-hash-from-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;;;ACIL,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","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 * 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}"]}
@@ -13,7 +13,32 @@ function createProjectContext(ctx) {
13
13
  };
14
14
  }
15
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
+
16
40
  exports.createProjectContext = createProjectContext;
41
+ exports.extractWorkspaceHashFromContext = extractWorkspaceHashFromContext;
17
42
  exports.isDesignProjectProjectCtx = isDesignProjectProjectCtx;
18
43
  //# sourceMappingURL=index.cjs.map
19
44
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/is-project-ctx.ts","../../src/utils/create-project-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","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"]}
1
+ {"version":3,"sources":["../../src/utils/is-project-ctx.ts","../../src/utils/create-project-context.ts","../../src/utils/extract-workspace-hash-from-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","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}"]}
@@ -19,4 +19,16 @@ declare function isDesignProjectProjectCtx(value: unknown): value is DesignProje
19
19
  */
20
20
  declare function createProjectContext(ctx: DesignProjectProjectCtx): Context;
21
21
 
22
- export { createProjectContext, isDesignProjectProjectCtx };
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
+ export { createProjectContext, extractWorkspaceHashFromContext, isDesignProjectProjectCtx };
@@ -19,4 +19,16 @@ declare function isDesignProjectProjectCtx(value: unknown): value is DesignProje
19
19
  */
20
20
  declare function createProjectContext(ctx: DesignProjectProjectCtx): Context;
21
21
 
22
- export { createProjectContext, isDesignProjectProjectCtx };
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
+ export { createProjectContext, extractWorkspaceHashFromContext, isDesignProjectProjectCtx };
@@ -11,6 +11,30 @@ function createProjectContext(ctx) {
11
11
  };
12
12
  }
13
13
 
14
- export { createProjectContext, isDesignProjectProjectCtx };
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
+ export { createProjectContext, extractWorkspaceHashFromContext, isDesignProjectProjectCtx };
15
39
  //# sourceMappingURL=index.js.map
16
40
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/is-project-ctx.ts","../../src/utils/create-project-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","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"]}
1
+ {"version":3,"sources":["../../src/utils/is-project-ctx.ts","../../src/utils/create-project-context.ts","../../src/utils/extract-workspace-hash-from-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","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}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zk-tech/ag-ui-core",
3
- "version": "0.0.1-alpha.5",
3
+ "version": "0.0.1-alpha.6",
4
4
  "description": "Extends from AG-UI core with more strict types",
5
5
  "license": "MIT",
6
6
  "author": "ZK Tech",