@zk-tech/ag-ui-core 0.0.1-alpha.4 → 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 +27 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -4
- package/dist/index.js.map +1 -1
- package/dist/protocol/index.cjs.map +1 -1
- package/dist/protocol/index.d.cts +2 -0
- package/dist/protocol/index.d.ts +2 -0
- package/dist/protocol/index.js.map +1 -1
- package/dist/utils/index.cjs +27 -3
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +18 -2
- package/dist/utils/index.d.ts +18 -2
- package/dist/utils/index.js +27 -4
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -12,16 +12,40 @@ function isDesignProjectProjectCtx(value) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
// src/utils/create-project-context.ts
|
|
15
|
-
function createProjectContext(
|
|
16
|
-
const projectCtx = { projectId };
|
|
15
|
+
function createProjectContext(ctx) {
|
|
17
16
|
return {
|
|
18
17
|
description: "project" /* Project */,
|
|
19
|
-
value: JSON.stringify(
|
|
18
|
+
value: JSON.stringify(ctx)
|
|
20
19
|
};
|
|
21
20
|
}
|
|
22
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
|
+
|
|
23
46
|
exports.DesignProjectCtxNamespace = DesignProjectCtxNamespace;
|
|
24
47
|
exports.createProjectContext = createProjectContext;
|
|
48
|
+
exports.extractWorkspaceHashFromContext = extractWorkspaceHashFromContext;
|
|
25
49
|
exports.isDesignProjectProjectCtx = isDesignProjectProjectCtx;
|
|
26
50
|
//# sourceMappingURL=index.cjs.map
|
|
27
51
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.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,
|
|
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,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um 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
|
@@ -10,14 +10,37 @@ function isDesignProjectProjectCtx(value) {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
// src/utils/create-project-context.ts
|
|
13
|
-
function createProjectContext(
|
|
14
|
-
const projectCtx = { projectId };
|
|
13
|
+
function createProjectContext(ctx) {
|
|
15
14
|
return {
|
|
16
15
|
description: "project" /* Project */,
|
|
17
|
-
value: JSON.stringify(
|
|
16
|
+
value: JSON.stringify(ctx)
|
|
18
17
|
};
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
|
|
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 };
|
|
22
45
|
//# sourceMappingURL=index.js.map
|
|
23
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,
|
|
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":["Design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;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}"]}
|
|
@@ -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"],"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 /** 草稿版本号, 如果没有那么则传递 undefined */\n workspaceHash: string | undefined;\n}"]}
|
package/dist/protocol/index.d.ts
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"],"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 /** 草稿版本号, 如果没有那么则传递 undefined */\n workspaceHash: string | undefined;\n}"]}
|
package/dist/utils/index.cjs
CHANGED
|
@@ -6,15 +6,39 @@ function isDesignProjectProjectCtx(value) {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
// src/utils/create-project-context.ts
|
|
9
|
-
function createProjectContext(
|
|
10
|
-
const projectCtx = { projectId };
|
|
9
|
+
function createProjectContext(ctx) {
|
|
11
10
|
return {
|
|
12
11
|
description: "project" /* Project */,
|
|
13
|
-
value: JSON.stringify(
|
|
12
|
+
value: JSON.stringify(ctx)
|
|
14
13
|
};
|
|
15
14
|
}
|
|
16
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
|
+
|
|
17
40
|
exports.createProjectContext = createProjectContext;
|
|
41
|
+
exports.extractWorkspaceHashFromContext = extractWorkspaceHashFromContext;
|
|
18
42
|
exports.isDesignProjectProjectCtx = isDesignProjectProjectCtx;
|
|
19
43
|
//# sourceMappingURL=index.cjs.map
|
|
20
44
|
//# sourceMappingURL=index.cjs.map
|
package/dist/utils/index.cjs.map
CHANGED
|
@@ -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,
|
|
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}"]}
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -7,12 +7,28 @@ import { Context } from '@ag-ui/core';
|
|
|
7
7
|
|
|
8
8
|
declare function isDesignProjectProjectCtx(value: unknown): value is DesignProjectProjectCtx;
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Create project context for AG-UI RunAgentInput
|
|
12
|
+
*/
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* Create a project context item for AG-UI RunAgentInput
|
|
12
16
|
*
|
|
13
17
|
* @param projectId - The project ID
|
|
14
18
|
* @returns Context item with namespace 'project' and projectId in value
|
|
15
19
|
*/
|
|
16
|
-
declare function createProjectContext(
|
|
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;
|
|
17
33
|
|
|
18
|
-
export { createProjectContext, isDesignProjectProjectCtx };
|
|
34
|
+
export { createProjectContext, extractWorkspaceHashFromContext, isDesignProjectProjectCtx };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -7,12 +7,28 @@ import { Context } from '@ag-ui/core';
|
|
|
7
7
|
|
|
8
8
|
declare function isDesignProjectProjectCtx(value: unknown): value is DesignProjectProjectCtx;
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Create project context for AG-UI RunAgentInput
|
|
12
|
+
*/
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* Create a project context item for AG-UI RunAgentInput
|
|
12
16
|
*
|
|
13
17
|
* @param projectId - The project ID
|
|
14
18
|
* @returns Context item with namespace 'project' and projectId in value
|
|
15
19
|
*/
|
|
16
|
-
declare function createProjectContext(
|
|
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;
|
|
17
33
|
|
|
18
|
-
export { createProjectContext, isDesignProjectProjectCtx };
|
|
34
|
+
export { createProjectContext, extractWorkspaceHashFromContext, isDesignProjectProjectCtx };
|
package/dist/utils/index.js
CHANGED
|
@@ -4,14 +4,37 @@ function isDesignProjectProjectCtx(value) {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
// src/utils/create-project-context.ts
|
|
7
|
-
function createProjectContext(
|
|
8
|
-
const projectCtx = { projectId };
|
|
7
|
+
function createProjectContext(ctx) {
|
|
9
8
|
return {
|
|
10
9
|
description: "project" /* Project */,
|
|
11
|
-
value: JSON.stringify(
|
|
10
|
+
value: JSON.stringify(ctx)
|
|
12
11
|
};
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
|
|
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 };
|
|
16
39
|
//# sourceMappingURL=index.js.map
|
|
17
40
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -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,
|
|
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}"]}
|