@copilotkit/shared 2.0.0-rc.2 → 2.0.0-rc.20
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 +3 -14
- package/dist/a2ui-envelope.cjs +2 -2
- package/dist/a2ui-envelope.cjs.map +1 -1
- package/dist/a2ui-envelope.d.cts +1 -1
- package/dist/a2ui-envelope.d.cts.map +1 -1
- package/dist/a2ui-envelope.d.mts +1 -1
- package/dist/a2ui-envelope.d.mts.map +1 -1
- package/dist/a2ui-envelope.mjs +2 -2
- package/dist/a2ui-envelope.mjs.map +1 -1
- package/dist/a2ui-prompts.cjs +21 -62
- package/dist/a2ui-prompts.cjs.map +1 -1
- package/dist/a2ui-prompts.d.cts +8 -1
- package/dist/a2ui-prompts.d.cts.map +1 -1
- package/dist/a2ui-prompts.d.mts +8 -1
- package/dist/a2ui-prompts.d.mts.map +1 -1
- package/dist/a2ui-prompts.mjs +22 -62
- package/dist/a2ui-prompts.mjs.map +1 -1
- package/dist/finalize-events.cjs +16 -0
- package/dist/finalize-events.cjs.map +1 -1
- package/dist/finalize-events.d.cts.map +1 -1
- package/dist/finalize-events.d.mts.map +1 -1
- package/dist/finalize-events.mjs +16 -0
- package/dist/finalize-events.mjs.map +1 -1
- package/dist/generative-ui/basic-functions.cjs +1 -1
- package/dist/generative-ui/basic-functions.cjs.map +1 -1
- package/dist/generative-ui/basic-functions.mjs +1 -1
- package/dist/generative-ui/basic-functions.mjs.map +1 -1
- package/dist/generative-ui/child-refs.cjs +3 -3
- package/dist/generative-ui/child-refs.cjs.map +1 -1
- package/dist/generative-ui/child-refs.d.cts.map +1 -1
- package/dist/generative-ui/child-refs.d.mts.map +1 -1
- package/dist/generative-ui/child-refs.mjs +3 -3
- package/dist/generative-ui/child-refs.mjs.map +1 -1
- package/dist/generative-ui/compact-schema.cjs +187 -0
- package/dist/generative-ui/compact-schema.cjs.map +1 -0
- package/dist/generative-ui/compact-schema.d.cts +55 -0
- package/dist/generative-ui/compact-schema.d.cts.map +1 -0
- package/dist/generative-ui/compact-schema.d.mts +55 -0
- package/dist/generative-ui/compact-schema.d.mts.map +1 -0
- package/dist/generative-ui/compact-schema.mjs +185 -0
- package/dist/generative-ui/compact-schema.mjs.map +1 -0
- package/dist/generative-ui/prompt-spec.cjs +225 -0
- package/dist/generative-ui/prompt-spec.cjs.map +1 -0
- package/dist/generative-ui/prompt-spec.d.cts +94 -0
- package/dist/generative-ui/prompt-spec.d.cts.map +1 -0
- package/dist/generative-ui/prompt-spec.d.mts +94 -0
- package/dist/generative-ui/prompt-spec.d.mts.map +1 -0
- package/dist/generative-ui/prompt-spec.mjs +220 -0
- package/dist/generative-ui/prompt-spec.mjs.map +1 -0
- package/dist/generative-ui/prompt.cjs +10 -36
- package/dist/generative-ui/prompt.cjs.map +1 -1
- package/dist/generative-ui/prompt.d.cts +2 -1
- package/dist/generative-ui/prompt.d.cts.map +1 -1
- package/dist/generative-ui/prompt.d.mts +2 -1
- package/dist/generative-ui/prompt.d.mts.map +1 -1
- package/dist/generative-ui/prompt.mjs +12 -38
- package/dist/generative-ui/prompt.mjs.map +1 -1
- package/dist/generative-ui/render-ui-args.cjs +1 -0
- package/dist/generative-ui/render-ui-args.cjs.map +1 -1
- package/dist/generative-ui/render-ui-args.d.cts.map +1 -1
- package/dist/generative-ui/render-ui-args.d.mts.map +1 -1
- package/dist/generative-ui/render-ui-args.mjs +1 -0
- package/dist/generative-ui/render-ui-args.mjs.map +1 -1
- package/dist/generative-ui/schema-render.cjs +242 -0
- package/dist/generative-ui/schema-render.cjs.map +1 -0
- package/dist/generative-ui/schema-render.d.cts +44 -0
- package/dist/generative-ui/schema-render.d.cts.map +1 -0
- package/dist/generative-ui/schema-render.d.mts +44 -0
- package/dist/generative-ui/schema-render.d.mts.map +1 -0
- package/dist/generative-ui/schema-render.mjs +239 -0
- package/dist/generative-ui/schema-render.mjs.map +1 -0
- package/dist/generative-ui/types.cjs +2 -2
- package/dist/generative-ui/types.cjs.map +1 -1
- package/dist/generative-ui/types.d.cts +7 -7
- package/dist/generative-ui/types.d.cts.map +1 -1
- package/dist/generative-ui/types.d.mts +7 -7
- package/dist/generative-ui/types.d.mts.map +1 -1
- package/dist/generative-ui/types.mjs +2 -2
- package/dist/generative-ui/types.mjs.map +1 -1
- package/dist/generative-ui/validate-operation.cjs +2 -2
- package/dist/generative-ui/validate-operation.cjs.map +1 -1
- package/dist/generative-ui/validate-operation.mjs +2 -2
- package/dist/generative-ui/validate-operation.mjs.map +1 -1
- package/dist/index.cjs +17 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -9
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +10 -9
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +9 -7
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +839 -447
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/standard-schema.cjs +20 -7
- package/dist/standard-schema.cjs.map +1 -1
- package/dist/standard-schema.d.cts +15 -16
- package/dist/standard-schema.d.cts.map +1 -1
- package/dist/standard-schema.d.mts +15 -16
- package/dist/standard-schema.d.mts.map +1 -1
- package/dist/standard-schema.mjs +20 -8
- package/dist/standard-schema.mjs.map +1 -1
- package/dist/telemetry/lambda-client.cjs +1 -1
- package/dist/telemetry/lambda-client.cjs.map +1 -1
- package/dist/telemetry/lambda-client.d.cts.map +1 -1
- package/dist/telemetry/lambda-client.d.mts.map +1 -1
- package/dist/telemetry/lambda-client.mjs +1 -1
- package/dist/telemetry/lambda-client.mjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.cjs +3 -6
- package/dist/telemetry/telemetry-disabled.cjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.d.cts +0 -5
- package/dist/telemetry/telemetry-disabled.d.cts.map +1 -1
- package/dist/telemetry/telemetry-disabled.d.mts +0 -5
- package/dist/telemetry/telemetry-disabled.d.mts.map +1 -1
- package/dist/telemetry/telemetry-disabled.mjs +4 -6
- package/dist/telemetry/telemetry-disabled.mjs.map +1 -1
- package/dist/types/message.d.cts +1 -18
- package/dist/types/message.d.cts.map +1 -1
- package/dist/types/message.d.mts +1 -18
- package/dist/types/message.d.mts.map +1 -1
- package/dist/utils/errors.cjs +5 -42
- package/dist/utils/errors.cjs.map +1 -1
- package/dist/utils/errors.d.cts +16 -34
- package/dist/utils/errors.d.cts.map +1 -1
- package/dist/utils/errors.d.mts +16 -34
- package/dist/utils/errors.d.mts.map +1 -1
- package/dist/utils/errors.mjs +6 -41
- package/dist/utils/errors.mjs.map +1 -1
- package/dist/utils/index.cjs +1 -2
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +4 -5
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.mts +4 -5
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +4 -5
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/json-schema.cjs +4 -79
- package/dist/utils/json-schema.cjs.map +1 -1
- package/dist/utils/json-schema.d.cts +1 -4
- package/dist/utils/json-schema.d.cts.map +1 -1
- package/dist/utils/json-schema.d.mts +1 -4
- package/dist/utils/json-schema.d.mts.map +1 -1
- package/dist/utils/json-schema.mjs +5 -78
- package/dist/utils/json-schema.mjs.map +1 -1
- package/dist/utils/process-env.cjs +14 -0
- package/dist/utils/process-env.cjs.map +1 -0
- package/dist/utils/process-env.d.cts +10 -0
- package/dist/utils/process-env.d.cts.map +1 -0
- package/dist/utils/process-env.d.mts +10 -0
- package/dist/utils/process-env.d.mts.map +1 -0
- package/dist/utils/process-env.mjs +13 -0
- package/dist/utils/process-env.mjs.map +1 -0
- package/dist/utils/random-id.cjs +13 -26
- package/dist/utils/random-id.cjs.map +1 -1
- package/dist/utils/random-id.d.cts +6 -3
- package/dist/utils/random-id.d.cts.map +1 -1
- package/dist/utils/random-id.d.mts +6 -3
- package/dist/utils/random-id.d.mts.map +1 -1
- package/dist/utils/random-id.mjs +14 -25
- package/dist/utils/random-id.mjs.map +1 -1
- package/package.json +8 -32
- package/scripts/verify-cjs-exports.cjs +1 -1
- package/src/__tests__/a2ui-envelope.test.ts +18 -13
- package/src/__tests__/a2ui-prompts.test.ts +47 -14
- package/src/__tests__/fixtures/prompt-goldens.json +354 -0
- package/src/__tests__/prompt-spec.test.ts +191 -0
- package/src/__tests__/root-entry-browser-safety.test.ts +5 -7
- package/src/__tests__/schema-render.test.ts +245 -0
- package/src/__tests__/standard-schema.test.ts +61 -101
- package/src/a2ui-envelope.ts +7 -6
- package/src/a2ui-prompts.ts +47 -96
- package/src/finalize-events.ts +16 -0
- package/src/generative-ui/__tests__/render-ui-args.test.ts +7 -7
- package/src/generative-ui/__tests__/validate-operation.test.ts +19 -13
- package/src/generative-ui/basic-functions.ts +1 -1
- package/src/generative-ui/child-refs.ts +5 -4
- package/src/generative-ui/compact-schema.ts +277 -0
- package/src/generative-ui/index.ts +3 -0
- package/src/generative-ui/prompt-spec.ts +335 -0
- package/src/generative-ui/prompt.ts +25 -75
- package/src/generative-ui/render-ui-args.ts +3 -0
- package/src/generative-ui/schema-render.ts +377 -0
- package/src/generative-ui/types.ts +10 -7
- package/src/generative-ui/validate-operation.ts +2 -2
- package/src/index.ts +3 -16
- package/src/standard-schema.ts +24 -27
- package/src/telemetry/lambda-client.ts +8 -3
- package/src/telemetry/model-host.test.ts +2 -5
- package/src/telemetry/telemetry-disabled.ts +7 -12
- package/src/types/message.ts +1 -19
- package/src/utils/__tests__/errors.test.ts +44 -0
- package/src/utils/__tests__/json-schema.test.ts +3 -479
- package/src/utils/__tests__/process-env.test.ts +22 -0
- package/src/utils/__tests__/random-id.test.ts +37 -0
- package/src/utils/errors.ts +28 -85
- package/src/utils/index.ts +1 -2
- package/src/utils/json-schema.ts +5 -152
- package/src/utils/process-env.ts +14 -0
- package/src/utils/random-id.ts +17 -37
- package/tsconfig.json +3 -1
- package/tsdown.config.ts +2 -19
- package/dist/event-transforms/index.cjs +0 -15
- package/dist/event-transforms/index.d.cts +0 -4
- package/dist/event-transforms/index.d.mts +0 -4
- package/dist/event-transforms/index.mjs +0 -5
- package/dist/event-transforms/open-generative-ui-middleware.cjs +0 -286
- package/dist/event-transforms/open-generative-ui-middleware.cjs.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.d.cts +0 -60
- package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.d.mts +0 -60
- package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.mjs +0 -283
- package/dist/event-transforms/open-generative-ui-middleware.mjs.map +0 -1
- package/dist/event-transforms/recorded-events.cjs +0 -59
- package/dist/event-transforms/recorded-events.cjs.map +0 -1
- package/dist/event-transforms/recorded-events.d.cts +0 -23
- package/dist/event-transforms/recorded-events.d.cts.map +0 -1
- package/dist/event-transforms/recorded-events.d.mts +0 -23
- package/dist/event-transforms/recorded-events.d.mts.map +0 -1
- package/dist/event-transforms/recorded-events.mjs +0 -58
- package/dist/event-transforms/recorded-events.mjs.map +0 -1
- package/dist/telemetry/events.d.cts +0 -72
- package/dist/telemetry/events.d.cts.map +0 -1
- package/dist/telemetry/events.d.mts +0 -72
- package/dist/telemetry/events.d.mts.map +0 -1
- package/dist/telemetry/index.cjs +0 -18
- package/dist/telemetry/index.d.cts +0 -5
- package/dist/telemetry/index.d.mts +0 -5
- package/dist/telemetry/index.mjs +0 -6
- package/dist/telemetry/telemetry-client.cjs +0 -165
- package/dist/telemetry/telemetry-client.cjs.map +0 -1
- package/dist/telemetry/telemetry-client.d.cts +0 -87
- package/dist/telemetry/telemetry-client.d.cts.map +0 -1
- package/dist/telemetry/telemetry-client.d.mts +0 -87
- package/dist/telemetry/telemetry-client.d.mts.map +0 -1
- package/dist/telemetry/telemetry-client.mjs +0 -164
- package/dist/telemetry/telemetry-client.mjs.map +0 -1
- package/dist/telemetry/utils.cjs +0 -14
- package/dist/telemetry/utils.cjs.map +0 -1
- package/dist/telemetry/utils.mjs +0 -13
- package/dist/telemetry/utils.mjs.map +0 -1
- package/dist/utils/conditions.cjs +0 -32
- package/dist/utils/conditions.cjs.map +0 -1
- package/dist/utils/conditions.d.cts +0 -31
- package/dist/utils/conditions.d.cts.map +0 -1
- package/dist/utils/conditions.d.mts +0 -31
- package/dist/utils/conditions.d.mts.map +0 -1
- package/dist/utils/conditions.mjs +0 -31
- package/dist/utils/conditions.mjs.map +0 -1
- package/dist/utils/console-styling.cjs +0 -91
- package/dist/utils/console-styling.cjs.map +0 -1
- package/dist/utils/console-styling.d.cts +0 -65
- package/dist/utils/console-styling.d.cts.map +0 -1
- package/dist/utils/console-styling.d.mts +0 -65
- package/dist/utils/console-styling.d.mts.map +0 -1
- package/dist/utils/console-styling.mjs +0 -85
- package/dist/utils/console-styling.mjs.map +0 -1
- package/src/__tests__/zod-regression.test.ts +0 -319
- package/src/event-transforms/index.ts +0 -5
- package/src/event-transforms/open-generative-ui-middleware.ts +0 -392
- package/src/event-transforms/recorded-events.test.ts +0 -166
- package/src/event-transforms/recorded-events.ts +0 -74
- package/src/telemetry/events.ts +0 -68
- package/src/telemetry/index.ts +0 -9
- package/src/telemetry/telemetry-blank-license-identity.test.ts +0 -128
- package/src/telemetry/telemetry-client.test.ts +0 -798
- package/src/telemetry/telemetry-client.ts +0 -328
- package/src/telemetry/utils.ts +0 -15
- package/src/utils/__tests__/conditions.test.ts +0 -161
- package/src/utils/conditions.ts +0 -116
- package/src/utils/console-styling.ts +0 -126
package/src/utils/index.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export * from "./clipboard";
|
|
2
|
-
export * from "./conditions";
|
|
3
|
-
export * from "./console-styling";
|
|
4
2
|
export * from "./errors";
|
|
5
3
|
export * from "./json-schema";
|
|
6
4
|
export * from "./inspector-metadata";
|
|
@@ -8,6 +6,7 @@ export * from "./inspector-learning";
|
|
|
8
6
|
export * from "./inspector-visibility";
|
|
9
7
|
export * from "./types";
|
|
10
8
|
export * from "./random-id";
|
|
9
|
+
export * from "./process-env";
|
|
11
10
|
export * from "./requests";
|
|
12
11
|
export * from "./row-render-keys";
|
|
13
12
|
|
package/src/utils/json-schema.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Parameter } from "../types";
|
|
1
|
+
import type { Parameter } from "../types";
|
|
3
2
|
|
|
4
3
|
export type JSONSchemaString = {
|
|
5
4
|
type: "string";
|
|
@@ -233,6 +232,10 @@ function convertAttribute(attribute: Parameter): JSONSchema {
|
|
|
233
232
|
...(properties && { properties }),
|
|
234
233
|
...(required && required.length > 0 && { required }),
|
|
235
234
|
};
|
|
235
|
+
case "string[]":
|
|
236
|
+
case "number[]":
|
|
237
|
+
case "boolean[]":
|
|
238
|
+
case undefined:
|
|
236
239
|
default:
|
|
237
240
|
// Handle arrays of primitive types and undefined attribute.type
|
|
238
241
|
if (attribute.type?.endsWith("[]")) {
|
|
@@ -250,153 +253,3 @@ function convertAttribute(attribute: Parameter): JSONSchema {
|
|
|
250
253
|
};
|
|
251
254
|
}
|
|
252
255
|
}
|
|
253
|
-
|
|
254
|
-
export function convertJsonSchemaToZodSchema(
|
|
255
|
-
jsonSchema: any,
|
|
256
|
-
required: boolean,
|
|
257
|
-
definitions?: Record<string, any>,
|
|
258
|
-
visitedRefs?: Set<string>,
|
|
259
|
-
): z.ZodSchema {
|
|
260
|
-
// Resolve $ref references
|
|
261
|
-
if (jsonSchema.$ref && definitions) {
|
|
262
|
-
const refPath = jsonSchema.$ref.replace(
|
|
263
|
-
/^#\/\$defs\/|^#\/definitions\//,
|
|
264
|
-
"",
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
// Detect circular $ref cycles
|
|
268
|
-
const refs = visitedRefs ?? new Set<string>();
|
|
269
|
-
if (refs.has(refPath)) {
|
|
270
|
-
console.warn(
|
|
271
|
-
`[CopilotKit] Circular $ref detected for "${refPath}" — falling back to z.any()`,
|
|
272
|
-
);
|
|
273
|
-
let schema = z.any();
|
|
274
|
-
if (jsonSchema.description) {
|
|
275
|
-
schema = schema.describe(jsonSchema.description);
|
|
276
|
-
}
|
|
277
|
-
return required ? schema : schema.optional();
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const resolved = definitions[refPath];
|
|
281
|
-
if (resolved) {
|
|
282
|
-
// Clone the set so sibling branches don't see each other's visited refs
|
|
283
|
-
const nextRefs = new Set(refs);
|
|
284
|
-
nextRefs.add(refPath);
|
|
285
|
-
return convertJsonSchemaToZodSchema(
|
|
286
|
-
resolved,
|
|
287
|
-
required,
|
|
288
|
-
definitions,
|
|
289
|
-
nextRefs,
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// Collect top-level definitions for $ref resolution
|
|
295
|
-
const defs = definitions ?? jsonSchema.$defs ?? jsonSchema.definitions;
|
|
296
|
-
|
|
297
|
-
// Handle null-union types like ["string", "null"]
|
|
298
|
-
if (Array.isArray(jsonSchema.type)) {
|
|
299
|
-
const types = jsonSchema.type as string[];
|
|
300
|
-
const hasNull = types.includes("null");
|
|
301
|
-
const nonNullTypes = types.filter((t: string) => t !== "null");
|
|
302
|
-
const resolvedType = nonNullTypes.length > 0 ? nonNullTypes[0] : "string";
|
|
303
|
-
const innerSchema = convertJsonSchemaToZodSchema(
|
|
304
|
-
{ ...jsonSchema, type: resolvedType },
|
|
305
|
-
true,
|
|
306
|
-
defs,
|
|
307
|
-
visitedRefs,
|
|
308
|
-
);
|
|
309
|
-
let schema = hasNull ? z.union([innerSchema, z.null()]) : innerSchema;
|
|
310
|
-
if (jsonSchema.description) {
|
|
311
|
-
schema = schema.describe(jsonSchema.description);
|
|
312
|
-
}
|
|
313
|
-
return required ? schema : schema.optional();
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// Handle anyOf / oneOf as z.union
|
|
317
|
-
const unionVariants = jsonSchema.anyOf ?? jsonSchema.oneOf;
|
|
318
|
-
if (Array.isArray(unionVariants) && unionVariants.length > 0) {
|
|
319
|
-
if (unionVariants.length === 1) {
|
|
320
|
-
return convertJsonSchemaToZodSchema(
|
|
321
|
-
unionVariants[0],
|
|
322
|
-
required,
|
|
323
|
-
defs,
|
|
324
|
-
visitedRefs,
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
const schemas = unionVariants.map((v: any) =>
|
|
328
|
-
convertJsonSchemaToZodSchema(v, true, defs, visitedRefs),
|
|
329
|
-
);
|
|
330
|
-
let schema = z.union(
|
|
331
|
-
schemas as [z.ZodSchema, z.ZodSchema, ...z.ZodSchema[]],
|
|
332
|
-
);
|
|
333
|
-
if (jsonSchema.description) {
|
|
334
|
-
schema = schema.describe(jsonSchema.description);
|
|
335
|
-
}
|
|
336
|
-
return required ? schema : schema.optional();
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
if (jsonSchema.type === "object") {
|
|
340
|
-
const spec: { [key: string]: z.ZodSchema } = {};
|
|
341
|
-
|
|
342
|
-
if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
|
|
343
|
-
return !required ? z.object(spec).optional() : z.object(spec);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
347
|
-
spec[key] = convertJsonSchemaToZodSchema(
|
|
348
|
-
value,
|
|
349
|
-
jsonSchema.required ? jsonSchema.required.includes(key) : false,
|
|
350
|
-
defs,
|
|
351
|
-
visitedRefs,
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
let schema = z.object(spec).describe(jsonSchema.description);
|
|
355
|
-
return required ? schema : schema.optional();
|
|
356
|
-
} else if (jsonSchema.type === "string") {
|
|
357
|
-
if (jsonSchema.enum && jsonSchema.enum.length > 0) {
|
|
358
|
-
let schema = z
|
|
359
|
-
.enum(jsonSchema.enum as [string, ...string[]])
|
|
360
|
-
.describe(jsonSchema.description);
|
|
361
|
-
return required ? schema : schema.optional();
|
|
362
|
-
}
|
|
363
|
-
let schema = z.string().describe(jsonSchema.description);
|
|
364
|
-
return required ? schema : schema.optional();
|
|
365
|
-
} else if (jsonSchema.type === "number" || jsonSchema.type === "integer") {
|
|
366
|
-
let schema = z.number().describe(jsonSchema.description);
|
|
367
|
-
return required ? schema : schema.optional();
|
|
368
|
-
} else if (jsonSchema.type === "boolean") {
|
|
369
|
-
let schema = z.boolean().describe(jsonSchema.description);
|
|
370
|
-
return required ? schema : schema.optional();
|
|
371
|
-
} else if (jsonSchema.type === "array") {
|
|
372
|
-
let itemSchema = convertJsonSchemaToZodSchema(
|
|
373
|
-
jsonSchema.items,
|
|
374
|
-
true,
|
|
375
|
-
defs,
|
|
376
|
-
visitedRefs,
|
|
377
|
-
);
|
|
378
|
-
let schema = z.array(itemSchema).describe(jsonSchema.description);
|
|
379
|
-
return required ? schema : schema.optional();
|
|
380
|
-
} else if (jsonSchema.type === "null") {
|
|
381
|
-
let schema = z.null().describe(jsonSchema.description);
|
|
382
|
-
return required ? schema : schema.optional();
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// Fallback: accept any value rather than throwing
|
|
386
|
-
console.warn(
|
|
387
|
-
`[CopilotKit] Unsupported JSON schema type "${jsonSchema.type ?? "unknown"}" — falling back to z.any()`,
|
|
388
|
-
);
|
|
389
|
-
let schema = z.any();
|
|
390
|
-
if (jsonSchema.description) {
|
|
391
|
-
schema = schema.describe(jsonSchema.description);
|
|
392
|
-
}
|
|
393
|
-
return required ? schema : schema.optional();
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
export function getZodParameters<T extends [] | Parameter[] | undefined>(
|
|
397
|
-
parameters: T,
|
|
398
|
-
): any {
|
|
399
|
-
if (!parameters) return z.object({});
|
|
400
|
-
const jsonParams = actionParametersToJsonSchema(parameters);
|
|
401
|
-
return convertJsonSchemaToZodSchema(jsonParams, true);
|
|
402
|
-
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The process environment, or an empty object where there is no `process`
|
|
3
|
+
* (Cloudflare Workers without `nodejs_compat`, browsers). Read it on each use
|
|
4
|
+
* rather than caching it, so later changes to `process.env` are seen.
|
|
5
|
+
*/
|
|
6
|
+
export function processEnv(): Record<string, string | undefined> {
|
|
7
|
+
return (
|
|
8
|
+
(
|
|
9
|
+
globalThis as {
|
|
10
|
+
process?: { env?: Record<string, string | undefined> };
|
|
11
|
+
}
|
|
12
|
+
).process?.env ?? {}
|
|
13
|
+
);
|
|
14
|
+
}
|
package/src/utils/random-id.ts
CHANGED
|
@@ -1,45 +1,25 @@
|
|
|
1
|
-
import { v4 as uuidv4, validate, v5 as uuidv5 } from "uuid";
|
|
2
|
-
|
|
3
1
|
export function randomId() {
|
|
4
|
-
return "ck-" +
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function randomUUID() {
|
|
8
|
-
return uuidv4();
|
|
2
|
+
return "ck-" + randomUUID();
|
|
9
3
|
}
|
|
10
4
|
|
|
11
5
|
/**
|
|
12
|
-
*
|
|
6
|
+
* Returns an RFC 4122 version 4 UUID. Uses `crypto.randomUUID()` when it
|
|
7
|
+
* exists, and builds the UUID from `crypto.getRandomValues()` when it does not
|
|
8
|
+
* (React Native's Hermes has no `randomUUID`).
|
|
13
9
|
*/
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
export function randomUUID(): string {
|
|
11
|
+
const crypto = globalThis.crypto;
|
|
12
|
+
if (typeof crypto?.randomUUID === "function") {
|
|
13
|
+
return crypto.randomUUID();
|
|
17
14
|
}
|
|
18
|
-
if (
|
|
19
|
-
|
|
15
|
+
if (typeof crypto?.getRandomValues !== "function") {
|
|
16
|
+
throw new Error(
|
|
17
|
+
"crypto.getRandomValues() is not available. In React Native, install a polyfill such as react-native-get-random-values.",
|
|
18
|
+
);
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function dataToUUID(input: string | object, namespace?: string): string {
|
|
32
|
-
const BASE_NAMESPACE = "e4b01160-ff74-4c6e-9b27-d53cd930fe8e";
|
|
33
|
-
// Since namespace needs to be a uuid, we are creating a uuid for it.
|
|
34
|
-
const boundNamespace = namespace
|
|
35
|
-
? uuidv5(namespace, BASE_NAMESPACE)
|
|
36
|
-
: BASE_NAMESPACE;
|
|
37
|
-
|
|
38
|
-
const stringInput =
|
|
39
|
-
typeof input === "string" ? input : JSON.stringify(toSerializable(input));
|
|
40
|
-
return uuidv5(stringInput, boundNamespace);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function isValidUUID(uuid: string) {
|
|
44
|
-
return validate(uuid);
|
|
20
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
21
|
+
bytes[6] = (bytes[6]! & 0x0f) | 0x40;
|
|
22
|
+
bytes[8] = (bytes[8]! & 0x3f) | 0x80;
|
|
23
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0"));
|
|
24
|
+
return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(6, 8).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10).join("")}`;
|
|
45
25
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "
|
|
2
|
+
"extends": "@copilotkit/typescript-config/base.json",
|
|
3
3
|
"include": ["."],
|
|
4
4
|
"compilerOptions": {
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "Bundler",
|
|
5
7
|
"target": "es2017",
|
|
6
8
|
"lib": ["es2017", "dom"],
|
|
7
9
|
"resolveJsonModule": true
|
package/tsdown.config.ts
CHANGED
|
@@ -2,13 +2,7 @@ import { defineConfig } from "tsdown";
|
|
|
2
2
|
|
|
3
3
|
export default defineConfig([
|
|
4
4
|
{
|
|
5
|
-
|
|
6
|
-
// The browser-facing root must not re-export either (#4151).
|
|
7
|
-
entry: [
|
|
8
|
-
"src/index.ts",
|
|
9
|
-
"src/telemetry/index.ts",
|
|
10
|
-
"src/event-transforms/index.ts",
|
|
11
|
-
],
|
|
5
|
+
entry: ["src/index.ts"],
|
|
12
6
|
format: ["esm", "cjs"],
|
|
13
7
|
dts: true,
|
|
14
8
|
sourcemap: true,
|
|
@@ -24,23 +18,12 @@ export default defineConfig([
|
|
|
24
18
|
sourcemap: true,
|
|
25
19
|
target: "es2018",
|
|
26
20
|
outDir: "dist",
|
|
27
|
-
external: [
|
|
28
|
-
"zod",
|
|
29
|
-
"graphql",
|
|
30
|
-
"uuid",
|
|
31
|
-
"@ag-ui/core",
|
|
32
|
-
"@ag-ui/client",
|
|
33
|
-
"partial-json",
|
|
34
|
-
],
|
|
21
|
+
external: ["@ag-ui/core", "@ag-ui/client", "partial-json"],
|
|
35
22
|
outputOptions(options) {
|
|
36
23
|
options.entryFileNames = "[name].umd.js";
|
|
37
24
|
options.globals = {
|
|
38
|
-
zod: "Zod",
|
|
39
|
-
graphql: "GraphQL",
|
|
40
|
-
uuid: "UUID",
|
|
41
25
|
"@ag-ui/core": "AgUICore",
|
|
42
26
|
"@ag-ui/client": "AgUIClient",
|
|
43
|
-
"@segment/analytics-node": "SegmentAnalyticsNode",
|
|
44
27
|
"partial-json": "PartialJSON",
|
|
45
28
|
};
|
|
46
29
|
return options;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_open_generative_ui_middleware = require('./open-generative-ui-middleware.cjs');
|
|
4
|
-
const require_recorded_events = require('./recorded-events.cjs');
|
|
5
|
-
let _ag_ui_a2ui_middleware = require("@ag-ui/a2ui-middleware");
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, 'A2UIMiddleware', {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return _ag_ui_a2ui_middleware.A2UIMiddleware;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
exports.ArgsParser = require_open_generative_ui_middleware.ArgsParser;
|
|
14
|
-
exports.OpenGenerativeUIMiddleware = require_open_generative_ui_middleware.OpenGenerativeUIMiddleware;
|
|
15
|
-
exports.transformRecordedEvents = require_recorded_events.transformRecordedEvents;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware } from "./open-generative-ui-middleware.cjs";
|
|
2
|
-
import { RecordedEventTransformOptions, transformRecordedEvents } from "./recorded-events.cjs";
|
|
3
|
-
import { A2UIMiddleware, A2UIMiddlewareConfig } from "@ag-ui/a2ui-middleware";
|
|
4
|
-
export { A2UIMiddleware, type A2UIMiddlewareConfig, ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware, RecordedEventTransformOptions, transformRecordedEvents };
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware } from "./open-generative-ui-middleware.mjs";
|
|
2
|
-
import { RecordedEventTransformOptions, transformRecordedEvents } from "./recorded-events.mjs";
|
|
3
|
-
import { A2UIMiddleware, A2UIMiddlewareConfig } from "@ag-ui/a2ui-middleware";
|
|
4
|
-
export { A2UIMiddleware, type A2UIMiddlewareConfig, ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware, RecordedEventTransformOptions, transformRecordedEvents };
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ArgsParser, OpenGenerativeUIMiddleware } from "./open-generative-ui-middleware.mjs";
|
|
2
|
-
import { transformRecordedEvents } from "./recorded-events.mjs";
|
|
3
|
-
import { A2UIMiddleware } from "@ag-ui/a2ui-middleware";
|
|
4
|
-
|
|
5
|
-
export { A2UIMiddleware, ArgsParser, OpenGenerativeUIMiddleware, transformRecordedEvents };
|
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
|
-
let _ag_ui_client = require("@ag-ui/client");
|
|
3
|
-
let rxjs = require("rxjs");
|
|
4
|
-
let clarinet = require("clarinet");
|
|
5
|
-
clarinet = require_runtime.__toESM(clarinet);
|
|
6
|
-
|
|
7
|
-
//#region src/event-transforms/open-generative-ui-middleware.ts
|
|
8
|
-
const TOOL_NAME = "generateSandboxedUi";
|
|
9
|
-
const ACTIVITY_TYPE = "open-generative-ui";
|
|
10
|
-
/**
|
|
11
|
-
* Tracks incremental JSON parsing state for a single tool call's arguments.
|
|
12
|
-
* Emits activity events via the onEvent callback as parameters complete.
|
|
13
|
-
*/
|
|
14
|
-
var ArgsParser = class {
|
|
15
|
-
constructor(toolCallId, onEvent) {
|
|
16
|
-
this.currentKey = null;
|
|
17
|
-
this.depth = 0;
|
|
18
|
-
this.currentArrayKey = null;
|
|
19
|
-
this.snapshotEmitted = false;
|
|
20
|
-
this.streamingHtmlKey = false;
|
|
21
|
-
this.htmlEmittedLength = 0;
|
|
22
|
-
this.htmlArrayEmitted = false;
|
|
23
|
-
this.params = {};
|
|
24
|
-
this.messageId = `${toolCallId}-activity`;
|
|
25
|
-
this.onEvent = onEvent;
|
|
26
|
-
this.parser = clarinet.default.parser();
|
|
27
|
-
this.parser.onopenobject = (key) => {
|
|
28
|
-
this.depth++;
|
|
29
|
-
if (key !== void 0 && this.depth === 1) {
|
|
30
|
-
this.currentKey = key;
|
|
31
|
-
this.initHtmlStreaming(key);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
this.parser.onkey = (key) => {
|
|
35
|
-
if (this.depth === 1) {
|
|
36
|
-
this.currentKey = key;
|
|
37
|
-
this.initHtmlStreaming(key);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
this.parser.onvalue = (value) => {
|
|
41
|
-
if (this.depth === 1 && this.currentKey) if (this.currentArrayKey) {
|
|
42
|
-
const strValue = String(value);
|
|
43
|
-
if (this.currentArrayKey === "jsExpressions") {
|
|
44
|
-
if (!this.params.jsExpressions) this.params.jsExpressions = [];
|
|
45
|
-
this.params.jsExpressions.push(strValue);
|
|
46
|
-
} else if (this.currentArrayKey === "placeholderMessages") {
|
|
47
|
-
if (!this.params.placeholderMessages) this.params.placeholderMessages = [];
|
|
48
|
-
this.params.placeholderMessages.push(strValue);
|
|
49
|
-
}
|
|
50
|
-
this.emitArrayItemDelta(this.currentArrayKey, strValue);
|
|
51
|
-
} else if (this.streamingHtmlKey) {
|
|
52
|
-
const fullHtml = value != null ? String(value) : "";
|
|
53
|
-
this.params.html = fullHtml || void 0;
|
|
54
|
-
this.emitPendingHtml(fullHtml);
|
|
55
|
-
this.emitParamDelta("htmlComplete", true);
|
|
56
|
-
this.streamingHtmlKey = false;
|
|
57
|
-
} else this.setParam(this.currentKey, value);
|
|
58
|
-
};
|
|
59
|
-
this.parser.onopenarray = () => {
|
|
60
|
-
if (this.depth === 1 && this.currentKey) {
|
|
61
|
-
const key = this.currentKey;
|
|
62
|
-
if (key === "jsExpressions" || key === "placeholderMessages") {
|
|
63
|
-
this.currentArrayKey = key;
|
|
64
|
-
if (key === "jsExpressions") this.params.jsExpressions = [];
|
|
65
|
-
else this.params.placeholderMessages = [];
|
|
66
|
-
this.emitParamDelta(key, []);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
this.parser.onclosearray = () => {
|
|
71
|
-
if (this.depth === 1) {
|
|
72
|
-
if (this.currentArrayKey === "jsExpressions") this.emitParamDelta("jsExpressionsComplete", true);
|
|
73
|
-
this.currentArrayKey = null;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
this.parser.oncloseobject = () => {
|
|
77
|
-
this.depth--;
|
|
78
|
-
};
|
|
79
|
-
this.parser.onerror = (err) => {
|
|
80
|
-
console.warn("[OpenGenerativeUI] JSON parse error in streaming args, resuming:", err?.message ?? err);
|
|
81
|
-
this.parser.error = null;
|
|
82
|
-
this.parser.resume();
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
write(chunk) {
|
|
86
|
-
this.parser.write(chunk);
|
|
87
|
-
this.flushHtmlChunks();
|
|
88
|
-
}
|
|
89
|
-
initHtmlStreaming(key) {
|
|
90
|
-
if (key === "html") {
|
|
91
|
-
this.streamingHtmlKey = true;
|
|
92
|
-
this.htmlEmittedLength = 0;
|
|
93
|
-
this.htmlArrayEmitted = false;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Read clarinet's internal textNode buffer to emit html chunks incrementally.
|
|
98
|
-
* Called after every write() so partial string content is emitted as it streams in.
|
|
99
|
-
*/
|
|
100
|
-
flushHtmlChunks() {
|
|
101
|
-
if (!this.streamingHtmlKey) return;
|
|
102
|
-
const textNode = this.parser.textNode;
|
|
103
|
-
if (typeof textNode !== "string") return;
|
|
104
|
-
if (textNode.length === this.htmlEmittedLength) return;
|
|
105
|
-
this.emitPendingHtml(textNode);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Emit accumulated html content since the last emission.
|
|
109
|
-
* Called by flushHtmlChunks and directly when html completes.
|
|
110
|
-
*/
|
|
111
|
-
emitPendingHtml(textNode) {
|
|
112
|
-
const newContent = textNode.slice(this.htmlEmittedLength);
|
|
113
|
-
if (newContent.length === 0) return;
|
|
114
|
-
if (!this.htmlArrayEmitted) {
|
|
115
|
-
this.htmlArrayEmitted = true;
|
|
116
|
-
this.emitParamDelta("html", []);
|
|
117
|
-
}
|
|
118
|
-
this.emitArrayItemDelta("html", newContent);
|
|
119
|
-
this.htmlEmittedLength = textNode.length;
|
|
120
|
-
}
|
|
121
|
-
setParam(key, value) {
|
|
122
|
-
switch (key) {
|
|
123
|
-
case "initialHeight":
|
|
124
|
-
this.params.initialHeight = typeof value === "number" ? value : void 0;
|
|
125
|
-
if (this.snapshotEmitted) this.emitParamDelta("initialHeight", this.params.initialHeight);
|
|
126
|
-
else this.emitSnapshot();
|
|
127
|
-
break;
|
|
128
|
-
case "css":
|
|
129
|
-
this.params.css = value != null ? String(value) : void 0;
|
|
130
|
-
this.emitParamDelta("css", this.params.css);
|
|
131
|
-
this.emitParamDelta("cssComplete", true);
|
|
132
|
-
break;
|
|
133
|
-
case "jsFunctions":
|
|
134
|
-
this.params.jsFunctions = value != null ? String(value) : void 0;
|
|
135
|
-
this.emitParamDelta("jsFunctions", this.params.jsFunctions);
|
|
136
|
-
this.emitParamDelta("jsFunctionsComplete", true);
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
emitSnapshot() {
|
|
141
|
-
if (this.snapshotEmitted) return;
|
|
142
|
-
this.snapshotEmitted = true;
|
|
143
|
-
const event = {
|
|
144
|
-
type: _ag_ui_client.EventType.ACTIVITY_SNAPSHOT,
|
|
145
|
-
messageId: this.messageId,
|
|
146
|
-
activityType: ACTIVITY_TYPE,
|
|
147
|
-
content: {
|
|
148
|
-
initialHeight: this.params.initialHeight,
|
|
149
|
-
generating: true
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
this.onEvent(event);
|
|
153
|
-
}
|
|
154
|
-
emitParamDelta(key, value) {
|
|
155
|
-
if (value === void 0) return;
|
|
156
|
-
this.emitSnapshot();
|
|
157
|
-
const event = {
|
|
158
|
-
type: _ag_ui_client.EventType.ACTIVITY_DELTA,
|
|
159
|
-
messageId: this.messageId,
|
|
160
|
-
activityType: ACTIVITY_TYPE,
|
|
161
|
-
patch: [{
|
|
162
|
-
op: "add",
|
|
163
|
-
path: `/${key}`,
|
|
164
|
-
value
|
|
165
|
-
}]
|
|
166
|
-
};
|
|
167
|
-
this.onEvent(event);
|
|
168
|
-
}
|
|
169
|
-
emitArrayItemDelta(arrayKey, value) {
|
|
170
|
-
this.emitSnapshot();
|
|
171
|
-
const event = {
|
|
172
|
-
type: _ag_ui_client.EventType.ACTIVITY_DELTA,
|
|
173
|
-
messageId: this.messageId,
|
|
174
|
-
activityType: ACTIVITY_TYPE,
|
|
175
|
-
patch: [{
|
|
176
|
-
op: "add",
|
|
177
|
-
path: `/${arrayKey}/-`,
|
|
178
|
-
value
|
|
179
|
-
}]
|
|
180
|
-
};
|
|
181
|
-
this.onEvent(event);
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
var OpenGenerativeUIMiddleware = class extends _ag_ui_client.Middleware {
|
|
185
|
-
run(input, next) {
|
|
186
|
-
return this.processStream(this.runNextWithState(input, next));
|
|
187
|
-
}
|
|
188
|
-
processStream(source) {
|
|
189
|
-
return new rxjs.Observable((subscriber) => {
|
|
190
|
-
let heldRunFinished = null;
|
|
191
|
-
const activeParsers = /* @__PURE__ */ new Map();
|
|
192
|
-
const heldToolCallEvents = /* @__PURE__ */ new Map();
|
|
193
|
-
const flushedToolCalls = /* @__PURE__ */ new Set();
|
|
194
|
-
const flushHeldEvents = (toolCallId) => {
|
|
195
|
-
if (flushedToolCalls.has(toolCallId)) return;
|
|
196
|
-
flushedToolCalls.add(toolCallId);
|
|
197
|
-
const held = heldToolCallEvents.get(toolCallId);
|
|
198
|
-
if (held) {
|
|
199
|
-
for (const e of held) subscriber.next(e);
|
|
200
|
-
heldToolCallEvents.delete(toolCallId);
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
const subscription = source.subscribe({
|
|
204
|
-
next: (eventWithState) => {
|
|
205
|
-
const event = eventWithState.event;
|
|
206
|
-
if (heldRunFinished) {
|
|
207
|
-
subscriber.next(heldRunFinished.event);
|
|
208
|
-
heldRunFinished = null;
|
|
209
|
-
}
|
|
210
|
-
if (event.type === _ag_ui_client.EventType.RUN_FINISHED) {
|
|
211
|
-
heldRunFinished = eventWithState;
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
if (event.type === _ag_ui_client.EventType.TOOL_CALL_START) {
|
|
215
|
-
const startEvent = event;
|
|
216
|
-
if (startEvent.toolCallName === TOOL_NAME) {
|
|
217
|
-
heldToolCallEvents.set(startEvent.toolCallId, [event]);
|
|
218
|
-
activeParsers.set(startEvent.toolCallId, new ArgsParser(startEvent.toolCallId, (activityEvent) => {
|
|
219
|
-
subscriber.next(activityEvent);
|
|
220
|
-
flushHeldEvents(startEvent.toolCallId);
|
|
221
|
-
}));
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
if (event.type === _ag_ui_client.EventType.TOOL_CALL_ARGS) {
|
|
226
|
-
const argsEvent = event;
|
|
227
|
-
const parser = activeParsers.get(argsEvent.toolCallId);
|
|
228
|
-
if (parser) {
|
|
229
|
-
if (!flushedToolCalls.has(argsEvent.toolCallId)) heldToolCallEvents.get(argsEvent.toolCallId).push(event);
|
|
230
|
-
else subscriber.next(event);
|
|
231
|
-
parser.write(argsEvent.delta);
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
if (event.type === _ag_ui_client.EventType.TOOL_CALL_END) {
|
|
236
|
-
const endEvent = event;
|
|
237
|
-
const parser = activeParsers.get(endEvent.toolCallId);
|
|
238
|
-
if (parser) {
|
|
239
|
-
const completeEvent = {
|
|
240
|
-
type: _ag_ui_client.EventType.ACTIVITY_DELTA,
|
|
241
|
-
messageId: parser.messageId,
|
|
242
|
-
activityType: ACTIVITY_TYPE,
|
|
243
|
-
patch: [{
|
|
244
|
-
op: "add",
|
|
245
|
-
path: "/generating",
|
|
246
|
-
value: false
|
|
247
|
-
}]
|
|
248
|
-
};
|
|
249
|
-
subscriber.next(completeEvent);
|
|
250
|
-
if (!flushedToolCalls.has(endEvent.toolCallId)) heldToolCallEvents.get(endEvent.toolCallId).push(event);
|
|
251
|
-
else subscriber.next(event);
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
subscriber.next(event);
|
|
256
|
-
},
|
|
257
|
-
error: (err) => {
|
|
258
|
-
for (const [, events] of heldToolCallEvents) for (const event of events) subscriber.next(event);
|
|
259
|
-
heldToolCallEvents.clear();
|
|
260
|
-
if (heldRunFinished) {
|
|
261
|
-
subscriber.next(heldRunFinished.event);
|
|
262
|
-
heldRunFinished = null;
|
|
263
|
-
}
|
|
264
|
-
subscriber.error(err);
|
|
265
|
-
},
|
|
266
|
-
complete: () => {
|
|
267
|
-
heldToolCallEvents.forEach((_, toolCallId) => {
|
|
268
|
-
flushHeldEvents(toolCallId);
|
|
269
|
-
});
|
|
270
|
-
if (heldRunFinished) {
|
|
271
|
-
subscriber.next(heldRunFinished.event);
|
|
272
|
-
heldRunFinished = null;
|
|
273
|
-
}
|
|
274
|
-
activeParsers.clear();
|
|
275
|
-
subscriber.complete();
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
return () => subscription.unsubscribe();
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
//#endregion
|
|
284
|
-
exports.ArgsParser = ArgsParser;
|
|
285
|
-
exports.OpenGenerativeUIMiddleware = OpenGenerativeUIMiddleware;
|
|
286
|
-
//# sourceMappingURL=open-generative-ui-middleware.cjs.map
|