@copilotkit/runtime 2.0.0-rc.3 → 2.0.0-rc.31
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 +19 -1
- package/dist/agent/converters/aisdk.cjs +0 -1
- package/dist/agent/converters/aisdk.cjs.map +1 -1
- package/dist/agent/converters/tanstack.cjs +1 -2
- package/dist/agent/converters/tanstack.cjs.map +1 -1
- package/dist/agent/converters/tanstack.mjs +1 -1
- package/dist/agent/converters/tanstack.mjs.map +1 -1
- package/dist/agent/index.cjs +9 -19
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +1 -9
- package/dist/agent/index.d.cts.map +1 -1
- package/dist/agent/index.d.mts +1 -9
- package/dist/agent/index.d.mts.map +1 -1
- package/dist/agent/index.mjs +10 -18
- package/dist/agent/index.mjs.map +1 -1
- package/dist/agent/learned-skills.cjs +0 -1
- package/dist/agent/learned-skills.cjs.map +1 -1
- package/dist/agent/state-delta.cjs +0 -1
- package/dist/agent/state-delta.cjs.map +1 -1
- package/dist/agent/url-download.cjs +0 -1
- package/dist/agent/url-download.cjs.map +1 -1
- package/dist/index.cjs +20 -10
- package/dist/index.d.cts +6 -3
- package/dist/index.d.mts +6 -3
- package/dist/index.mjs +5 -2
- package/dist/node.cjs +1 -2
- package/dist/node.d.cts +2 -2
- package/dist/node.d.mts +2 -2
- package/dist/node.mjs +2 -2
- package/dist/runtime/core/channel-manager.cjs +0 -1
- package/dist/runtime/core/channel-manager.cjs.map +1 -1
- package/dist/runtime/core/debug-event-bus.cjs +0 -1
- package/dist/runtime/core/debug-event-bus.cjs.map +1 -1
- package/dist/runtime/core/fetch-handler.cjs +3 -4
- package/dist/runtime/core/fetch-handler.cjs.map +1 -1
- package/dist/runtime/core/fetch-handler.mjs.map +1 -1
- package/dist/runtime/core/logger.cjs +85 -13
- package/dist/runtime/core/logger.cjs.map +1 -1
- package/dist/runtime/core/logger.d.cts +21 -8
- package/dist/runtime/core/logger.d.cts.map +1 -1
- package/dist/runtime/core/logger.d.mts +21 -8
- package/dist/runtime/core/logger.d.mts.map +1 -1
- package/dist/runtime/core/logger.mjs +85 -10
- package/dist/runtime/core/logger.mjs.map +1 -1
- package/dist/runtime/core/middleware-sse-parser.cjs +0 -1
- package/dist/runtime/core/middleware-sse-parser.cjs.map +1 -1
- package/dist/runtime/core/middleware.cjs +0 -1
- package/dist/runtime/core/middleware.cjs.map +1 -1
- package/dist/runtime/core/package-info.cjs +1 -1
- package/dist/runtime/core/package-info.mjs +1 -1
- package/dist/runtime/core/runtime.cjs +0 -1
- package/dist/runtime/core/runtime.cjs.map +1 -1
- package/dist/runtime/core/runtime.d.mts +1 -1
- package/dist/runtime/endpoints/auto-start-channels.cjs +0 -1
- package/dist/runtime/endpoints/auto-start-channels.cjs.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.cjs +0 -4
- package/dist/runtime/endpoints/node-fetch-handler.cjs.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.d.cts +1 -3
- package/dist/runtime/endpoints/node-fetch-handler.d.cts.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.d.mts +1 -3
- package/dist/runtime/endpoints/node-fetch-handler.d.mts.map +1 -1
- package/dist/runtime/endpoints/node-fetch-handler.mjs +1 -3
- package/dist/runtime/endpoints/node-fetch-handler.mjs.map +1 -1
- package/dist/runtime/event-transforms/index.d.cts +4 -0
- package/dist/runtime/event-transforms/index.d.mts +4 -0
- package/dist/runtime/event-transforms/index.mjs +5 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.cjs +277 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.cjs.map +1 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.d.cts +61 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.d.cts.map +1 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.d.mts +61 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.d.mts.map +1 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.mjs +276 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.mjs.map +1 -0
- package/dist/runtime/event-transforms/recorded-events.cjs +58 -0
- package/dist/runtime/event-transforms/recorded-events.cjs.map +1 -0
- package/dist/runtime/event-transforms/recorded-events.d.cts +23 -0
- package/dist/runtime/event-transforms/recorded-events.d.cts.map +1 -0
- package/dist/runtime/event-transforms/recorded-events.d.mts +23 -0
- package/dist/runtime/event-transforms/recorded-events.d.mts.map +1 -0
- package/dist/runtime/event-transforms/recorded-events.mjs +58 -0
- package/dist/runtime/event-transforms/recorded-events.mjs.map +1 -0
- package/dist/runtime/event-transforms/streaming-json-scanner.cjs +289 -0
- package/dist/runtime/event-transforms/streaming-json-scanner.cjs.map +1 -0
- package/dist/runtime/event-transforms/streaming-json-scanner.mjs +288 -0
- package/dist/runtime/event-transforms/streaming-json-scanner.mjs.map +1 -0
- package/dist/runtime/generative-ui/generative-ui-middleware.cjs +0 -1
- package/dist/runtime/generative-ui/generative-ui-middleware.cjs.map +1 -1
- package/dist/runtime/generative-ui/surface-writer.cjs +4 -5
- package/dist/runtime/generative-ui/surface-writer.cjs.map +1 -1
- package/dist/runtime/generative-ui/surface-writer.d.cts.map +1 -1
- package/dist/runtime/generative-ui/surface-writer.d.mts.map +1 -1
- package/dist/runtime/generative-ui/surface-writer.mjs +5 -5
- package/dist/runtime/generative-ui/surface-writer.mjs.map +1 -1
- package/dist/runtime/handlers/handle-connect.cjs.map +1 -1
- package/dist/runtime/handlers/handle-connect.mjs.map +1 -1
- package/dist/runtime/handlers/handle-inspector-learning.cjs +2 -3
- package/dist/runtime/handlers/handle-inspector-learning.cjs.map +1 -1
- package/dist/runtime/handlers/handle-inspector-metadata.cjs +2 -3
- package/dist/runtime/handlers/handle-inspector-metadata.cjs.map +1 -1
- package/dist/runtime/handlers/handle-run.cjs +3 -4
- package/dist/runtime/handlers/handle-run.cjs.map +1 -1
- package/dist/runtime/handlers/handle-run.mjs.map +1 -1
- package/dist/runtime/handlers/handle-stop.cjs +3 -4
- package/dist/runtime/handlers/handle-stop.cjs.map +1 -1
- package/dist/runtime/handlers/handle-suggest.cjs +0 -1
- package/dist/runtime/handlers/handle-suggest.cjs.map +1 -1
- package/dist/runtime/handlers/handle-transcribe.cjs +0 -1
- package/dist/runtime/handlers/handle-transcribe.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/annotate.cjs +2 -3
- package/dist/runtime/handlers/intelligence/annotate.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/memories.cjs +7 -8
- package/dist/runtime/handlers/intelligence/memories.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/run.cjs +0 -1
- package/dist/runtime/handlers/intelligence/run.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/run.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/thread-names.cjs +0 -1
- package/dist/runtime/handlers/intelligence/thread-names.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/threads.cjs +6 -7
- package/dist/runtime/handlers/intelligence/threads.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/threads.mjs.map +1 -1
- package/dist/runtime/handlers/shared/agent-utils.cjs +9 -9
- package/dist/runtime/handlers/shared/agent-utils.cjs.map +1 -1
- package/dist/runtime/handlers/shared/agent-utils.mjs +2 -1
- package/dist/runtime/handlers/shared/agent-utils.mjs.map +1 -1
- package/dist/runtime/handlers/shared/cloud-telemetry.cjs +0 -1
- package/dist/runtime/handlers/shared/cloud-telemetry.cjs.map +1 -1
- package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs +1 -1
- package/dist/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -1
- package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs +1 -1
- package/dist/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -1
- package/dist/runtime/handlers/shared/sse-response.cjs +72 -64
- package/dist/runtime/handlers/shared/sse-response.cjs.map +1 -1
- package/dist/runtime/handlers/shared/sse-response.mjs +72 -63
- package/dist/runtime/handlers/shared/sse-response.mjs.map +1 -1
- package/dist/runtime/handlers/sse/run.cjs.map +1 -1
- package/dist/runtime/handlers/sse/run.mjs.map +1 -1
- package/dist/runtime/index.d.cts +4 -9
- package/dist/runtime/index.d.mts +4 -9
- package/dist/runtime/intelligence-platform/client.cjs +0 -1
- package/dist/runtime/intelligence-platform/client.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/learning-management.cjs +7 -8
- package/dist/runtime/intelligence-platform/learning-management.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/learning-management.mjs +7 -7
- package/dist/runtime/intelligence-platform/learning-management.mjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/archive.cjs +104 -110
- package/dist/runtime/intelligence-platform/skill-registry/archive.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts +8 -2
- package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts +8 -2
- package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/archive.mjs +104 -109
- package/dist/runtime/intelligence-platform/skill-registry/archive.mjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/config.cjs +0 -1
- package/dist/runtime/intelligence-platform/skill-registry/config.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/registry.cjs +22 -19
- package/dist/runtime/intelligence-platform/skill-registry/registry.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/registry.d.cts.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/registry.d.mts.map +1 -1
- package/dist/runtime/intelligence-platform/skill-registry/registry.mjs +22 -19
- package/dist/runtime/intelligence-platform/skill-registry/registry.mjs.map +1 -1
- package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs +0 -1
- package/dist/runtime/intelligence-platform/thread-lock-heartbeat.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/trajectories.cjs +2 -3
- package/dist/runtime/intelligence-platform/trajectories.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/trajectories.mjs +2 -2
- package/dist/runtime/intelligence-platform/trajectories.mjs.map +1 -1
- package/dist/runtime/node.d.cts +1 -1
- package/dist/runtime/node.d.mts +1 -1
- package/dist/runtime/runner/agent-runner.cjs +0 -1
- package/dist/runtime/runner/agent-runner.cjs.map +1 -1
- package/dist/runtime/runner/in-memory.cjs +0 -1
- package/dist/runtime/runner/in-memory.cjs.map +1 -1
- package/dist/runtime/runner/intelligence.cjs +0 -1
- package/dist/runtime/runner/intelligence.cjs.map +1 -1
- package/dist/runtime/telemetry/disclosure.cjs +0 -1
- package/dist/runtime/telemetry/disclosure.cjs.map +1 -1
- package/dist/runtime/telemetry/disclosure.mjs.map +1 -1
- package/dist/runtime/telemetry/instance-created.cjs +7 -9
- package/dist/runtime/telemetry/instance-created.cjs.map +1 -1
- package/dist/runtime/telemetry/instance-created.mjs +7 -9
- package/dist/runtime/telemetry/instance-created.mjs.map +1 -1
- package/dist/runtime/telemetry/telemetry-client.cjs +0 -5
- package/dist/runtime/telemetry/telemetry-client.cjs.map +1 -1
- package/dist/runtime/telemetry/telemetry-client.mjs +0 -4
- package/dist/runtime/telemetry/telemetry-client.mjs.map +1 -1
- package/dist/runtime/telemetry/telemetry-identity.cjs +0 -1
- package/dist/runtime/telemetry/telemetry-identity.cjs.map +1 -1
- package/package.json +11 -19
- package/dist/_virtual/_rolldown/runtime.cjs +0 -29
- package/dist/runtime/index.d.cts.map +0 -1
- package/dist/runtime/index.d.mts.map +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
2
1
|
let _copilotkit_shared = require("@copilotkit/shared");
|
|
3
2
|
let _remix_run_node_fetch_server = require("@remix-run/node-fetch-server");
|
|
4
3
|
|
|
@@ -22,8 +21,6 @@ function createCopilotNodeHandler(handler) {
|
|
|
22
21
|
}
|
|
23
22
|
};
|
|
24
23
|
}
|
|
25
|
-
/** @deprecated Use `createCopilotNodeHandler` instead. */
|
|
26
|
-
const createNodeFetchHandler = createCopilotNodeHandler;
|
|
27
24
|
/**
|
|
28
25
|
* Build a Fetch Request from a Node IncomingMessage whose body stream has
|
|
29
26
|
* already been consumed by a body parser.
|
|
@@ -71,5 +68,4 @@ function synthesizeBody(body) {
|
|
|
71
68
|
|
|
72
69
|
//#endregion
|
|
73
70
|
exports.createCopilotNodeHandler = createCopilotNodeHandler;
|
|
74
|
-
exports.createNodeFetchHandler = createNodeFetchHandler;
|
|
75
71
|
//# sourceMappingURL=node-fetch-handler.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-fetch-handler.cjs","names":[],"sources":["../../../src/runtime/endpoints/node-fetch-handler.ts"],"sourcesContent":["/**\n * Generic Node ↔ Fetch bridge for CopilotKit runtime.\n *\n * Wraps a `CopilotRuntimeFetchHandler` as a Node HTTP handler using\n * `@remix-run/node-fetch-server` for reliable streaming and conversion.\n *\n * When body-parsing middleware (Express `express.json()`, NestJS's default\n * parser, …) runs first, the Node request stream is already consumed and\n * `req.body` holds the parsed content. Reading the exhausted stream would hang,\n * so that case re-serialises `req.body` into the Fetch `Request` instead.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime\";\n * import { createCopilotNodeHandler } from \"@copilotkit/runtime/node\";\n *\n * const handler = createCopilotRuntimeHandler({ runtime, basePath: \"/api/copilotkit\", cors: true });\n * const nodeHandler = createCopilotNodeHandler(handler);\n * createServer(nodeHandler).listen(3000);\n * ```\n */\n\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport {\n createHeaders,\n createRequest,\n sendResponse,\n} from \"@remix-run/node-fetch-server\";\nimport type { CopilotRuntimeFetchHandler } from \"../core/fetch-handler\";\nimport { logger } from \"@copilotkit/shared\";\n\nconst METHODS_WITHOUT_BODY = new Set([\"GET\", \"HEAD\", \"OPTIONS\"]);\n\nexport type NodeFetchHandler = (\n req: IncomingMessage,\n res: ServerResponse,\n) => Promise<void>;\n\nexport function createCopilotNodeHandler(\n handler: CopilotRuntimeFetchHandler,\n): NodeFetchHandler {\n return async (req: IncomingMessage, res: ServerResponse) => {\n try {\n const method = (req.method ?? \"GET\").toUpperCase();\n const fetchReq =\n !METHODS_WITHOUT_BODY.has(method) && hasPreParsedBody(req)\n ? buildPreParsedRequest(req, res)\n : createRequest(req, res);\n const fetchRes = await handler(fetchReq);\n await sendResponse(res, fetchRes);\n } catch (err: unknown) {\n logger.error({ err }, \"Error in Node fetch handler\");\n if (!res.headersSent) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n }\n };\n}\n\n
|
|
1
|
+
{"version":3,"file":"node-fetch-handler.cjs","names":[],"sources":["../../../src/runtime/endpoints/node-fetch-handler.ts"],"sourcesContent":["/**\n * Generic Node ↔ Fetch bridge for CopilotKit runtime.\n *\n * Wraps a `CopilotRuntimeFetchHandler` as a Node HTTP handler using\n * `@remix-run/node-fetch-server` for reliable streaming and conversion.\n *\n * When body-parsing middleware (Express `express.json()`, NestJS's default\n * parser, …) runs first, the Node request stream is already consumed and\n * `req.body` holds the parsed content. Reading the exhausted stream would hang,\n * so that case re-serialises `req.body` into the Fetch `Request` instead.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime\";\n * import { createCopilotNodeHandler } from \"@copilotkit/runtime/node\";\n *\n * const handler = createCopilotRuntimeHandler({ runtime, basePath: \"/api/copilotkit\", cors: true });\n * const nodeHandler = createCopilotNodeHandler(handler);\n * createServer(nodeHandler).listen(3000);\n * ```\n */\n\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport {\n createHeaders,\n createRequest,\n sendResponse,\n} from \"@remix-run/node-fetch-server\";\nimport type { CopilotRuntimeFetchHandler } from \"../core/fetch-handler\";\nimport { logger } from \"@copilotkit/shared\";\n\nconst METHODS_WITHOUT_BODY = new Set([\"GET\", \"HEAD\", \"OPTIONS\"]);\n\nexport type NodeFetchHandler = (\n req: IncomingMessage,\n res: ServerResponse,\n) => Promise<void>;\n\nexport function createCopilotNodeHandler(\n handler: CopilotRuntimeFetchHandler,\n): NodeFetchHandler {\n return async (req: IncomingMessage, res: ServerResponse) => {\n try {\n const method = (req.method ?? \"GET\").toUpperCase();\n const fetchReq =\n !METHODS_WITHOUT_BODY.has(method) && hasPreParsedBody(req)\n ? buildPreParsedRequest(req, res)\n : createRequest(req, res);\n const fetchRes = await handler(fetchReq);\n await sendResponse(res, fetchRes);\n } catch (err: unknown) {\n logger.error({ err }, \"Error in Node fetch handler\");\n if (!res.headersSent) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n }\n };\n}\n\n/**\n * Build a Fetch Request from a Node IncomingMessage whose body stream has\n * already been consumed by a body parser.\n *\n * The URL, headers and abort wiring match `createRequest` (the streaming path),\n * so a request routes the same way whether or not a parser ran first. In\n * particular the URL comes from `req.url`, which is what a mounting router\n * matched against; `originalUrl` still carries the mount prefix and would miss\n * the handler's `basePath`.\n */\nfunction buildPreParsedRequest(\n req: IncomingMessage & { body?: unknown },\n res: ServerResponse,\n): Request {\n const method = (req.method ?? \"GET\").toUpperCase();\n const headers = createHeaders(req);\n const protocol =\n \"encrypted\" in req.socket && req.socket.encrypted ? \"https:\" : \"http:\";\n const host = headers.get(\"host\") ?? \"localhost\";\n const url = new URL(req.url ?? \"/\", `${protocol}//${host}`);\n\n // Wire an AbortSignal so client disconnects propagate to the fetch handler\n const controller = new AbortController();\n res.on(\"close\", () => {\n if (!res.writableFinished) controller.abort();\n });\n\n const init: RequestInit = {\n method,\n headers,\n signal: controller.signal,\n };\n\n const { body, contentType } = synthesizeBody(req.body);\n if (contentType) {\n headers.set(\"content-type\", contentType);\n }\n headers.delete(\"content-length\");\n if (body !== undefined) {\n init.body = body;\n }\n\n return new Request(url, init);\n}\n\nfunction hasPreParsedBody(req: IncomingMessage & { body?: unknown }): boolean {\n if (req.body === undefined || req.body === null) return false;\n\n // Only `readableEnded` means \"a parser drained this stream to its end\".\n // `req.complete` and the private `_readableState.ended` are set by the HTTP\n // parser once the socket has all the bytes, whether or not anything read them.\n //\n // That distinction matters because `req.body` being set does not prove a parser\n // ran: body-parser 1.x (Express 4) assigns `req.body = req.body || {}` before\n // its own content-type checks, so a request it declines to parse — multipart\n // upload, text/plain — reaches us with `req.body === {}` and a full, unread\n // stream. Treating that as pre-parsed rebuilt the request from `{}` and\n // dropped the real payload.\n return Boolean(req.readableEnded);\n}\n\nfunction synthesizeBody(body: unknown): {\n body?: BodyInit;\n contentType?: string;\n} {\n if (Buffer.isBuffer(body) || body instanceof Uint8Array) {\n // Buffer/Uint8Array<ArrayBufferLike> are valid fetch bodies at runtime,\n // but the DOM lib's BodyInit only admits ArrayBuffer-backed views.\n return { body: body as BodyInit };\n }\n if (typeof body === \"string\") {\n return { body };\n }\n if (typeof body === \"object\" && body !== null) {\n return { body: JSON.stringify(body), contentType: \"application/json\" };\n }\n return {};\n}\n"],"mappings":";;;;AAgCA,MAAM,uBAAuB,IAAI,IAAI;CAAC;CAAO;CAAQ;CAAU,CAAC;AAOhE,SAAgB,yBACd,SACkB;AAClB,QAAO,OAAO,KAAsB,QAAwB;AAC1D,MAAI;GACF,MAAM,UAAU,IAAI,UAAU,OAAO,aAAa;AAMlD,wDAAmB,KADF,MAAM,QAHrB,CAAC,qBAAqB,IAAI,OAAO,IAAI,iBAAiB,IAAI,GACtD,sBAAsB,KAAK,IAAI,mDACjB,KAAK,IAAI,CACW,CACP;WAC1B,KAAc;AACrB,6BAAO,MAAM,EAAE,KAAK,EAAE,8BAA8B;AACpD,OAAI,CAAC,IAAI,aAAa;AACpB,QAAI,aAAa;AACjB,QAAI,IAAI,wBAAwB;;;;;;;;;;;;;;;AAgBxC,SAAS,sBACP,KACA,KACS;CACT,MAAM,UAAU,IAAI,UAAU,OAAO,aAAa;CAClD,MAAM,0DAAwB,IAAI;CAClC,MAAM,WACJ,eAAe,IAAI,UAAU,IAAI,OAAO,YAAY,WAAW;CACjE,MAAM,OAAO,QAAQ,IAAI,OAAO,IAAI;CACpC,MAAM,MAAM,IAAI,IAAI,IAAI,OAAO,KAAK,GAAG,SAAS,IAAI,OAAO;CAG3D,MAAM,aAAa,IAAI,iBAAiB;AACxC,KAAI,GAAG,eAAe;AACpB,MAAI,CAAC,IAAI,iBAAkB,YAAW,OAAO;GAC7C;CAEF,MAAM,OAAoB;EACxB;EACA;EACA,QAAQ,WAAW;EACpB;CAED,MAAM,EAAE,MAAM,gBAAgB,eAAe,IAAI,KAAK;AACtD,KAAI,YACF,SAAQ,IAAI,gBAAgB,YAAY;AAE1C,SAAQ,OAAO,iBAAiB;AAChC,KAAI,SAAS,OACX,MAAK,OAAO;AAGd,QAAO,IAAI,QAAQ,KAAK,KAAK;;AAG/B,SAAS,iBAAiB,KAAoD;AAC5E,KAAI,IAAI,SAAS,UAAa,IAAI,SAAS,KAAM,QAAO;AAYxD,QAAO,QAAQ,IAAI,cAAc;;AAGnC,SAAS,eAAe,MAGtB;AACA,KAAI,OAAO,SAAS,KAAK,IAAI,gBAAgB,WAG3C,QAAO,EAAQ,MAAkB;AAEnC,KAAI,OAAO,SAAS,SAClB,QAAO,EAAE,MAAM;AAEjB,KAAI,OAAO,SAAS,YAAY,SAAS,KACvC,QAAO;EAAE,MAAM,KAAK,UAAU,KAAK;EAAE,aAAa;EAAoB;AAExE,QAAO,EAAE"}
|
|
@@ -4,8 +4,6 @@ import { IncomingMessage, ServerResponse } from "node:http";
|
|
|
4
4
|
//#region src/runtime/endpoints/node-fetch-handler.d.ts
|
|
5
5
|
type NodeFetchHandler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
6
6
|
declare function createCopilotNodeHandler(handler: CopilotRuntimeFetchHandler): NodeFetchHandler;
|
|
7
|
-
/** @deprecated Use `createCopilotNodeHandler` instead. */
|
|
8
|
-
declare const createNodeFetchHandler: typeof createCopilotNodeHandler;
|
|
9
7
|
//#endregion
|
|
10
|
-
export { NodeFetchHandler, createCopilotNodeHandler
|
|
8
|
+
export { NodeFetchHandler, createCopilotNodeHandler };
|
|
11
9
|
//# sourceMappingURL=node-fetch-handler.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-fetch-handler.d.cts","names":[],"sources":["../../../src/runtime/endpoints/node-fetch-handler.ts"],"mappings":";;;;KAkCY,gBAAA,IACV,GAAA,EAAK,eAAA,EACL,GAAA,EAAK,cAAA,KACF,OAAA;AAAA,iBAEW,wBAAA,CACd,OAAA,EAAS,0BAAA,GACR,gBAAA
|
|
1
|
+
{"version":3,"file":"node-fetch-handler.d.cts","names":[],"sources":["../../../src/runtime/endpoints/node-fetch-handler.ts"],"mappings":";;;;KAkCY,gBAAA,IACV,GAAA,EAAK,eAAA,EACL,GAAA,EAAK,cAAA,KACF,OAAA;AAAA,iBAEW,wBAAA,CACd,OAAA,EAAS,0BAAA,GACR,gBAAA"}
|
|
@@ -4,8 +4,6 @@ import { IncomingMessage, ServerResponse } from "node:http";
|
|
|
4
4
|
//#region src/runtime/endpoints/node-fetch-handler.d.ts
|
|
5
5
|
type NodeFetchHandler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
6
6
|
declare function createCopilotNodeHandler(handler: CopilotRuntimeFetchHandler): NodeFetchHandler;
|
|
7
|
-
/** @deprecated Use `createCopilotNodeHandler` instead. */
|
|
8
|
-
declare const createNodeFetchHandler: typeof createCopilotNodeHandler;
|
|
9
7
|
//#endregion
|
|
10
|
-
export { NodeFetchHandler, createCopilotNodeHandler
|
|
8
|
+
export { NodeFetchHandler, createCopilotNodeHandler };
|
|
11
9
|
//# sourceMappingURL=node-fetch-handler.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-fetch-handler.d.mts","names":[],"sources":["../../../src/runtime/endpoints/node-fetch-handler.ts"],"mappings":";;;;KAkCY,gBAAA,IACV,GAAA,EAAK,eAAA,EACL,GAAA,EAAK,cAAA,KACF,OAAA;AAAA,iBAEW,wBAAA,CACd,OAAA,EAAS,0BAAA,GACR,gBAAA
|
|
1
|
+
{"version":3,"file":"node-fetch-handler.d.mts","names":[],"sources":["../../../src/runtime/endpoints/node-fetch-handler.ts"],"mappings":";;;;KAkCY,gBAAA,IACV,GAAA,EAAK,eAAA,EACL,GAAA,EAAK,cAAA,KACF,OAAA;AAAA,iBAEW,wBAAA,CACd,OAAA,EAAS,0BAAA,GACR,gBAAA"}
|
|
@@ -21,8 +21,6 @@ function createCopilotNodeHandler(handler) {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
/** @deprecated Use `createCopilotNodeHandler` instead. */
|
|
25
|
-
const createNodeFetchHandler = createCopilotNodeHandler;
|
|
26
24
|
/**
|
|
27
25
|
* Build a Fetch Request from a Node IncomingMessage whose body stream has
|
|
28
26
|
* already been consumed by a body parser.
|
|
@@ -69,5 +67,5 @@ function synthesizeBody(body) {
|
|
|
69
67
|
}
|
|
70
68
|
|
|
71
69
|
//#endregion
|
|
72
|
-
export { createCopilotNodeHandler
|
|
70
|
+
export { createCopilotNodeHandler };
|
|
73
71
|
//# sourceMappingURL=node-fetch-handler.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-fetch-handler.mjs","names":[],"sources":["../../../src/runtime/endpoints/node-fetch-handler.ts"],"sourcesContent":["/**\n * Generic Node ↔ Fetch bridge for CopilotKit runtime.\n *\n * Wraps a `CopilotRuntimeFetchHandler` as a Node HTTP handler using\n * `@remix-run/node-fetch-server` for reliable streaming and conversion.\n *\n * When body-parsing middleware (Express `express.json()`, NestJS's default\n * parser, …) runs first, the Node request stream is already consumed and\n * `req.body` holds the parsed content. Reading the exhausted stream would hang,\n * so that case re-serialises `req.body` into the Fetch `Request` instead.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime\";\n * import { createCopilotNodeHandler } from \"@copilotkit/runtime/node\";\n *\n * const handler = createCopilotRuntimeHandler({ runtime, basePath: \"/api/copilotkit\", cors: true });\n * const nodeHandler = createCopilotNodeHandler(handler);\n * createServer(nodeHandler).listen(3000);\n * ```\n */\n\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport {\n createHeaders,\n createRequest,\n sendResponse,\n} from \"@remix-run/node-fetch-server\";\nimport type { CopilotRuntimeFetchHandler } from \"../core/fetch-handler\";\nimport { logger } from \"@copilotkit/shared\";\n\nconst METHODS_WITHOUT_BODY = new Set([\"GET\", \"HEAD\", \"OPTIONS\"]);\n\nexport type NodeFetchHandler = (\n req: IncomingMessage,\n res: ServerResponse,\n) => Promise<void>;\n\nexport function createCopilotNodeHandler(\n handler: CopilotRuntimeFetchHandler,\n): NodeFetchHandler {\n return async (req: IncomingMessage, res: ServerResponse) => {\n try {\n const method = (req.method ?? \"GET\").toUpperCase();\n const fetchReq =\n !METHODS_WITHOUT_BODY.has(method) && hasPreParsedBody(req)\n ? buildPreParsedRequest(req, res)\n : createRequest(req, res);\n const fetchRes = await handler(fetchReq);\n await sendResponse(res, fetchRes);\n } catch (err: unknown) {\n logger.error({ err }, \"Error in Node fetch handler\");\n if (!res.headersSent) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n }\n };\n}\n\n
|
|
1
|
+
{"version":3,"file":"node-fetch-handler.mjs","names":[],"sources":["../../../src/runtime/endpoints/node-fetch-handler.ts"],"sourcesContent":["/**\n * Generic Node ↔ Fetch bridge for CopilotKit runtime.\n *\n * Wraps a `CopilotRuntimeFetchHandler` as a Node HTTP handler using\n * `@remix-run/node-fetch-server` for reliable streaming and conversion.\n *\n * When body-parsing middleware (Express `express.json()`, NestJS's default\n * parser, …) runs first, the Node request stream is already consumed and\n * `req.body` holds the parsed content. Reading the exhausted stream would hang,\n * so that case re-serialises `req.body` into the Fetch `Request` instead.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime\";\n * import { createCopilotNodeHandler } from \"@copilotkit/runtime/node\";\n *\n * const handler = createCopilotRuntimeHandler({ runtime, basePath: \"/api/copilotkit\", cors: true });\n * const nodeHandler = createCopilotNodeHandler(handler);\n * createServer(nodeHandler).listen(3000);\n * ```\n */\n\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport {\n createHeaders,\n createRequest,\n sendResponse,\n} from \"@remix-run/node-fetch-server\";\nimport type { CopilotRuntimeFetchHandler } from \"../core/fetch-handler\";\nimport { logger } from \"@copilotkit/shared\";\n\nconst METHODS_WITHOUT_BODY = new Set([\"GET\", \"HEAD\", \"OPTIONS\"]);\n\nexport type NodeFetchHandler = (\n req: IncomingMessage,\n res: ServerResponse,\n) => Promise<void>;\n\nexport function createCopilotNodeHandler(\n handler: CopilotRuntimeFetchHandler,\n): NodeFetchHandler {\n return async (req: IncomingMessage, res: ServerResponse) => {\n try {\n const method = (req.method ?? \"GET\").toUpperCase();\n const fetchReq =\n !METHODS_WITHOUT_BODY.has(method) && hasPreParsedBody(req)\n ? buildPreParsedRequest(req, res)\n : createRequest(req, res);\n const fetchRes = await handler(fetchReq);\n await sendResponse(res, fetchRes);\n } catch (err: unknown) {\n logger.error({ err }, \"Error in Node fetch handler\");\n if (!res.headersSent) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n }\n };\n}\n\n/**\n * Build a Fetch Request from a Node IncomingMessage whose body stream has\n * already been consumed by a body parser.\n *\n * The URL, headers and abort wiring match `createRequest` (the streaming path),\n * so a request routes the same way whether or not a parser ran first. In\n * particular the URL comes from `req.url`, which is what a mounting router\n * matched against; `originalUrl` still carries the mount prefix and would miss\n * the handler's `basePath`.\n */\nfunction buildPreParsedRequest(\n req: IncomingMessage & { body?: unknown },\n res: ServerResponse,\n): Request {\n const method = (req.method ?? \"GET\").toUpperCase();\n const headers = createHeaders(req);\n const protocol =\n \"encrypted\" in req.socket && req.socket.encrypted ? \"https:\" : \"http:\";\n const host = headers.get(\"host\") ?? \"localhost\";\n const url = new URL(req.url ?? \"/\", `${protocol}//${host}`);\n\n // Wire an AbortSignal so client disconnects propagate to the fetch handler\n const controller = new AbortController();\n res.on(\"close\", () => {\n if (!res.writableFinished) controller.abort();\n });\n\n const init: RequestInit = {\n method,\n headers,\n signal: controller.signal,\n };\n\n const { body, contentType } = synthesizeBody(req.body);\n if (contentType) {\n headers.set(\"content-type\", contentType);\n }\n headers.delete(\"content-length\");\n if (body !== undefined) {\n init.body = body;\n }\n\n return new Request(url, init);\n}\n\nfunction hasPreParsedBody(req: IncomingMessage & { body?: unknown }): boolean {\n if (req.body === undefined || req.body === null) return false;\n\n // Only `readableEnded` means \"a parser drained this stream to its end\".\n // `req.complete` and the private `_readableState.ended` are set by the HTTP\n // parser once the socket has all the bytes, whether or not anything read them.\n //\n // That distinction matters because `req.body` being set does not prove a parser\n // ran: body-parser 1.x (Express 4) assigns `req.body = req.body || {}` before\n // its own content-type checks, so a request it declines to parse — multipart\n // upload, text/plain — reaches us with `req.body === {}` and a full, unread\n // stream. Treating that as pre-parsed rebuilt the request from `{}` and\n // dropped the real payload.\n return Boolean(req.readableEnded);\n}\n\nfunction synthesizeBody(body: unknown): {\n body?: BodyInit;\n contentType?: string;\n} {\n if (Buffer.isBuffer(body) || body instanceof Uint8Array) {\n // Buffer/Uint8Array<ArrayBufferLike> are valid fetch bodies at runtime,\n // but the DOM lib's BodyInit only admits ArrayBuffer-backed views.\n return { body: body as BodyInit };\n }\n if (typeof body === \"string\") {\n return { body };\n }\n if (typeof body === \"object\" && body !== null) {\n return { body: JSON.stringify(body), contentType: \"application/json\" };\n }\n return {};\n}\n"],"mappings":";;;;AAgCA,MAAM,uBAAuB,IAAI,IAAI;CAAC;CAAO;CAAQ;CAAU,CAAC;AAOhE,SAAgB,yBACd,SACkB;AAClB,QAAO,OAAO,KAAsB,QAAwB;AAC1D,MAAI;GAC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M;AAEjB,KAAI,OAAO,SAAS,YAAY,SAAS,KACvC,QAAO;EAAE,MAAM,KAAK,UAAU,KAAK;EAAE,aAAa;EAAoB;AAExE,QAAO,EAAE"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware } from "./open-generative-ui-middleware.cjs";
|
|
2
|
+
import { RecordedEventTransformOptions, transformRecordedEvents } from "./recorded-events.cjs";
|
|
3
|
+
import { A2UIMiddleware, A2UIMiddlewareConfig as A2UIMiddlewareConfig$1 } from "@ag-ui/a2ui-middleware";
|
|
4
|
+
export { A2UIMiddleware, type A2UIMiddlewareConfig$1 as A2UIMiddlewareConfig };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware } from "./open-generative-ui-middleware.mjs";
|
|
2
|
+
import { RecordedEventTransformOptions, transformRecordedEvents } from "./recorded-events.mjs";
|
|
3
|
+
import { A2UIMiddleware as A2UIMiddleware$1, A2UIMiddlewareConfig as A2UIMiddlewareConfig$1 } from "@ag-ui/a2ui-middleware";
|
|
4
|
+
export { A2UIMiddleware$1 as A2UIMiddleware, type A2UIMiddlewareConfig$1 as A2UIMiddlewareConfig };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ArgsParser, OpenGenerativeUIMiddleware } from "./open-generative-ui-middleware.mjs";
|
|
2
|
+
import { transformRecordedEvents } from "./recorded-events.mjs";
|
|
3
|
+
import { A2UIMiddleware as A2UIMiddleware$1 } from "@ag-ui/a2ui-middleware";
|
|
4
|
+
|
|
5
|
+
export { A2UIMiddleware$1 as A2UIMiddleware };
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
const require_streaming_json_scanner = require('./streaming-json-scanner.cjs');
|
|
2
|
+
let rxjs = require("rxjs");
|
|
3
|
+
let _ag_ui_client = require("@ag-ui/client");
|
|
4
|
+
|
|
5
|
+
//#region src/runtime/event-transforms/open-generative-ui-middleware.ts
|
|
6
|
+
const TOOL_NAME = "generateSandboxedUi";
|
|
7
|
+
const ACTIVITY_TYPE = "open-generative-ui";
|
|
8
|
+
/**
|
|
9
|
+
* Tracks incremental JSON parsing state for a single tool call's arguments.
|
|
10
|
+
* Emits activity events via the onEvent callback as parameters complete.
|
|
11
|
+
*/
|
|
12
|
+
var ArgsParser = class {
|
|
13
|
+
constructor(toolCallId, onEvent) {
|
|
14
|
+
this.currentKey = null;
|
|
15
|
+
this.depth = 0;
|
|
16
|
+
this.currentArrayKey = null;
|
|
17
|
+
this.snapshotEmitted = false;
|
|
18
|
+
this.streamingHtmlKey = false;
|
|
19
|
+
this.htmlEmittedLength = 0;
|
|
20
|
+
this.htmlArrayEmitted = false;
|
|
21
|
+
this.params = {};
|
|
22
|
+
this.messageId = `${toolCallId}-activity`;
|
|
23
|
+
this.onEvent = onEvent;
|
|
24
|
+
this.scanner = new require_streaming_json_scanner.StreamingJsonScanner({
|
|
25
|
+
onOpenObject: () => {
|
|
26
|
+
this.depth++;
|
|
27
|
+
},
|
|
28
|
+
onKey: (key) => {
|
|
29
|
+
if (this.depth === 1) {
|
|
30
|
+
this.currentKey = key;
|
|
31
|
+
this.initHtmlStreaming(key);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
onValue: (value) => {
|
|
35
|
+
if (this.depth === 1 && this.currentKey) if (this.currentArrayKey) {
|
|
36
|
+
const strValue = String(value);
|
|
37
|
+
if (this.currentArrayKey === "jsExpressions") {
|
|
38
|
+
if (!this.params.jsExpressions) this.params.jsExpressions = [];
|
|
39
|
+
this.params.jsExpressions.push(strValue);
|
|
40
|
+
} else if (this.currentArrayKey === "placeholderMessages") {
|
|
41
|
+
if (!this.params.placeholderMessages) this.params.placeholderMessages = [];
|
|
42
|
+
this.params.placeholderMessages.push(strValue);
|
|
43
|
+
}
|
|
44
|
+
this.emitArrayItemDelta(this.currentArrayKey, strValue);
|
|
45
|
+
} else if (this.streamingHtmlKey) {
|
|
46
|
+
const fullHtml = value != null ? String(value) : "";
|
|
47
|
+
this.params.html = fullHtml || void 0;
|
|
48
|
+
this.emitPendingHtml(fullHtml);
|
|
49
|
+
this.emitParamDelta("htmlComplete", true);
|
|
50
|
+
this.streamingHtmlKey = false;
|
|
51
|
+
} else this.setParam(this.currentKey, value);
|
|
52
|
+
},
|
|
53
|
+
onOpenArray: () => {
|
|
54
|
+
if (this.depth === 1 && this.currentKey) {
|
|
55
|
+
const key = this.currentKey;
|
|
56
|
+
if (key === "jsExpressions" || key === "placeholderMessages") {
|
|
57
|
+
this.currentArrayKey = key;
|
|
58
|
+
if (key === "jsExpressions") this.params.jsExpressions = [];
|
|
59
|
+
else this.params.placeholderMessages = [];
|
|
60
|
+
this.emitParamDelta(key, []);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
onCloseArray: () => {
|
|
65
|
+
if (this.depth === 1) {
|
|
66
|
+
if (this.currentArrayKey === "jsExpressions") this.emitParamDelta("jsExpressionsComplete", true);
|
|
67
|
+
this.currentArrayKey = null;
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
onCloseObject: () => {
|
|
71
|
+
this.depth--;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
write(chunk) {
|
|
76
|
+
this.scanner.write(chunk);
|
|
77
|
+
this.flushHtmlChunks();
|
|
78
|
+
}
|
|
79
|
+
initHtmlStreaming(key) {
|
|
80
|
+
if (key === "html") {
|
|
81
|
+
this.streamingHtmlKey = true;
|
|
82
|
+
this.htmlEmittedLength = 0;
|
|
83
|
+
this.htmlArrayEmitted = false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Emit the html read so far while the html string streams in.
|
|
88
|
+
* Called after every write(). It reads only while the top-level `html`
|
|
89
|
+
* value is being read, so a nested string is never emitted as html.
|
|
90
|
+
*/
|
|
91
|
+
flushHtmlChunks() {
|
|
92
|
+
if (!this.streamingHtmlKey || this.depth !== 1) return;
|
|
93
|
+
const partialHtml = this.scanner.partialString;
|
|
94
|
+
if (partialHtml === void 0) return;
|
|
95
|
+
if (partialHtml.length === this.htmlEmittedLength) return;
|
|
96
|
+
this.emitPendingHtml(partialHtml);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Emit accumulated html content since the last emission.
|
|
100
|
+
* Called by flushHtmlChunks and directly when html completes.
|
|
101
|
+
*/
|
|
102
|
+
emitPendingHtml(html) {
|
|
103
|
+
const newContent = html.slice(this.htmlEmittedLength);
|
|
104
|
+
if (newContent.length === 0) return;
|
|
105
|
+
if (!this.htmlArrayEmitted) {
|
|
106
|
+
this.htmlArrayEmitted = true;
|
|
107
|
+
this.emitParamDelta("html", []);
|
|
108
|
+
}
|
|
109
|
+
this.emitArrayItemDelta("html", newContent);
|
|
110
|
+
this.htmlEmittedLength = html.length;
|
|
111
|
+
}
|
|
112
|
+
setParam(key, value) {
|
|
113
|
+
switch (key) {
|
|
114
|
+
case "initialHeight":
|
|
115
|
+
this.params.initialHeight = typeof value === "number" ? value : void 0;
|
|
116
|
+
if (this.snapshotEmitted) this.emitParamDelta("initialHeight", this.params.initialHeight);
|
|
117
|
+
else this.emitSnapshot();
|
|
118
|
+
break;
|
|
119
|
+
case "css":
|
|
120
|
+
this.params.css = value != null ? String(value) : void 0;
|
|
121
|
+
this.emitParamDelta("css", this.params.css);
|
|
122
|
+
this.emitParamDelta("cssComplete", true);
|
|
123
|
+
break;
|
|
124
|
+
case "jsFunctions":
|
|
125
|
+
this.params.jsFunctions = value != null ? String(value) : void 0;
|
|
126
|
+
this.emitParamDelta("jsFunctions", this.params.jsFunctions);
|
|
127
|
+
this.emitParamDelta("jsFunctionsComplete", true);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
emitSnapshot() {
|
|
132
|
+
if (this.snapshotEmitted) return;
|
|
133
|
+
this.snapshotEmitted = true;
|
|
134
|
+
const event = {
|
|
135
|
+
type: _ag_ui_client.EventType.ACTIVITY_SNAPSHOT,
|
|
136
|
+
messageId: this.messageId,
|
|
137
|
+
activityType: ACTIVITY_TYPE,
|
|
138
|
+
content: {
|
|
139
|
+
initialHeight: this.params.initialHeight,
|
|
140
|
+
generating: true
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
this.onEvent(event);
|
|
144
|
+
}
|
|
145
|
+
emitParamDelta(key, value) {
|
|
146
|
+
if (value === void 0) return;
|
|
147
|
+
this.emitSnapshot();
|
|
148
|
+
const event = {
|
|
149
|
+
type: _ag_ui_client.EventType.ACTIVITY_DELTA,
|
|
150
|
+
messageId: this.messageId,
|
|
151
|
+
activityType: ACTIVITY_TYPE,
|
|
152
|
+
patch: [{
|
|
153
|
+
op: "add",
|
|
154
|
+
path: `/${key}`,
|
|
155
|
+
value
|
|
156
|
+
}]
|
|
157
|
+
};
|
|
158
|
+
this.onEvent(event);
|
|
159
|
+
}
|
|
160
|
+
emitArrayItemDelta(arrayKey, value) {
|
|
161
|
+
this.emitSnapshot();
|
|
162
|
+
const event = {
|
|
163
|
+
type: _ag_ui_client.EventType.ACTIVITY_DELTA,
|
|
164
|
+
messageId: this.messageId,
|
|
165
|
+
activityType: ACTIVITY_TYPE,
|
|
166
|
+
patch: [{
|
|
167
|
+
op: "add",
|
|
168
|
+
path: `/${arrayKey}/-`,
|
|
169
|
+
value
|
|
170
|
+
}]
|
|
171
|
+
};
|
|
172
|
+
this.onEvent(event);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var OpenGenerativeUIMiddleware = class extends _ag_ui_client.Middleware {
|
|
176
|
+
run(input, next) {
|
|
177
|
+
return this.processStream(this.runNextWithState(input, next));
|
|
178
|
+
}
|
|
179
|
+
processStream(source) {
|
|
180
|
+
return new rxjs.Observable((subscriber) => {
|
|
181
|
+
let heldRunFinished = null;
|
|
182
|
+
const activeParsers = /* @__PURE__ */ new Map();
|
|
183
|
+
const heldToolCallEvents = /* @__PURE__ */ new Map();
|
|
184
|
+
const flushedToolCalls = /* @__PURE__ */ new Set();
|
|
185
|
+
const flushHeldEvents = (toolCallId) => {
|
|
186
|
+
if (flushedToolCalls.has(toolCallId)) return;
|
|
187
|
+
flushedToolCalls.add(toolCallId);
|
|
188
|
+
const held = heldToolCallEvents.get(toolCallId);
|
|
189
|
+
if (held) {
|
|
190
|
+
for (const e of held) subscriber.next(e);
|
|
191
|
+
heldToolCallEvents.delete(toolCallId);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
const subscription = source.subscribe({
|
|
195
|
+
next: (eventWithState) => {
|
|
196
|
+
const event = eventWithState.event;
|
|
197
|
+
if (heldRunFinished) {
|
|
198
|
+
subscriber.next(heldRunFinished.event);
|
|
199
|
+
heldRunFinished = null;
|
|
200
|
+
}
|
|
201
|
+
if (event.type === _ag_ui_client.EventType.RUN_FINISHED) {
|
|
202
|
+
heldRunFinished = eventWithState;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (event.type === _ag_ui_client.EventType.TOOL_CALL_START) {
|
|
206
|
+
const startEvent = event;
|
|
207
|
+
if (startEvent.toolCallName === TOOL_NAME) {
|
|
208
|
+
heldToolCallEvents.set(startEvent.toolCallId, [event]);
|
|
209
|
+
activeParsers.set(startEvent.toolCallId, new ArgsParser(startEvent.toolCallId, (activityEvent) => {
|
|
210
|
+
subscriber.next(activityEvent);
|
|
211
|
+
flushHeldEvents(startEvent.toolCallId);
|
|
212
|
+
}));
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (event.type === _ag_ui_client.EventType.TOOL_CALL_ARGS) {
|
|
217
|
+
const argsEvent = event;
|
|
218
|
+
const parser = activeParsers.get(argsEvent.toolCallId);
|
|
219
|
+
if (parser) {
|
|
220
|
+
if (!flushedToolCalls.has(argsEvent.toolCallId)) heldToolCallEvents.get(argsEvent.toolCallId).push(event);
|
|
221
|
+
else subscriber.next(event);
|
|
222
|
+
parser.write(argsEvent.delta);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (event.type === _ag_ui_client.EventType.TOOL_CALL_END) {
|
|
227
|
+
const endEvent = event;
|
|
228
|
+
const parser = activeParsers.get(endEvent.toolCallId);
|
|
229
|
+
if (parser) {
|
|
230
|
+
const completeEvent = {
|
|
231
|
+
type: _ag_ui_client.EventType.ACTIVITY_DELTA,
|
|
232
|
+
messageId: parser.messageId,
|
|
233
|
+
activityType: ACTIVITY_TYPE,
|
|
234
|
+
patch: [{
|
|
235
|
+
op: "add",
|
|
236
|
+
path: "/generating",
|
|
237
|
+
value: false
|
|
238
|
+
}]
|
|
239
|
+
};
|
|
240
|
+
subscriber.next(completeEvent);
|
|
241
|
+
if (!flushedToolCalls.has(endEvent.toolCallId)) heldToolCallEvents.get(endEvent.toolCallId).push(event);
|
|
242
|
+
else subscriber.next(event);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
subscriber.next(event);
|
|
247
|
+
},
|
|
248
|
+
error: (err) => {
|
|
249
|
+
for (const [, events] of heldToolCallEvents) for (const event of events) subscriber.next(event);
|
|
250
|
+
heldToolCallEvents.clear();
|
|
251
|
+
if (heldRunFinished) {
|
|
252
|
+
subscriber.next(heldRunFinished.event);
|
|
253
|
+
heldRunFinished = null;
|
|
254
|
+
}
|
|
255
|
+
subscriber.error(err);
|
|
256
|
+
},
|
|
257
|
+
complete: () => {
|
|
258
|
+
heldToolCallEvents.forEach((_, toolCallId) => {
|
|
259
|
+
flushHeldEvents(toolCallId);
|
|
260
|
+
});
|
|
261
|
+
if (heldRunFinished) {
|
|
262
|
+
subscriber.next(heldRunFinished.event);
|
|
263
|
+
heldRunFinished = null;
|
|
264
|
+
}
|
|
265
|
+
activeParsers.clear();
|
|
266
|
+
subscriber.complete();
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
return () => subscription.unsubscribe();
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
//#endregion
|
|
275
|
+
exports.ArgsParser = ArgsParser;
|
|
276
|
+
exports.OpenGenerativeUIMiddleware = OpenGenerativeUIMiddleware;
|
|
277
|
+
//# sourceMappingURL=open-generative-ui-middleware.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-generative-ui-middleware.cjs","names":["StreamingJsonScanner","EventType","Middleware","Observable"],"sources":["../../../src/runtime/event-transforms/open-generative-ui-middleware.ts"],"sourcesContent":["import type {\n RunAgentInput,\n AbstractAgent,\n BaseEvent,\n ToolCallStartEvent,\n ToolCallArgsEvent,\n ActivitySnapshotEventProps,\n ActivityDeltaEvent,\n} from \"@ag-ui/client\";\nimport { Middleware, EventType } from \"@ag-ui/client\";\nimport { Observable } from \"rxjs\";\nimport { StreamingJsonScanner } from \"./streaming-json-scanner\";\nimport type { JsonScalar } from \"./streaming-json-scanner\";\n\nconst TOOL_NAME = \"generateSandboxedUi\";\nconst ACTIVITY_TYPE = \"open-generative-ui\";\n\n/**\n * Parsed parameters from the generateSandboxedUi tool call.\n */\nexport interface GenerateSandboxedUIParams {\n initialHeight?: number;\n placeholderMessages?: string[];\n css?: string;\n html?: string;\n jsFunctions?: string;\n jsExpressions?: string[];\n}\n\n/**\n * Callback invoked by ArgsParser whenever a parameter (or array item) finishes parsing.\n */\nexport type OnParamEvent = (event: BaseEvent) => void;\n\n/**\n * Tracks incremental JSON parsing state for a single tool call's arguments.\n * Emits activity events via the onEvent callback as parameters complete.\n */\nexport class ArgsParser {\n private readonly scanner: StreamingJsonScanner;\n private currentKey: string | null = null;\n private depth = 0;\n private currentArrayKey: string | null = null;\n private snapshotEmitted = false;\n\n // Streaming html state. flushHtmlChunks reads scanner.partialString to emit\n // the html in chunks while it streams in.\n private streamingHtmlKey = false;\n private htmlEmittedLength = 0;\n private htmlArrayEmitted = false;\n\n public readonly params: GenerateSandboxedUIParams = {};\n public readonly messageId: string;\n private readonly onEvent: OnParamEvent;\n\n constructor(toolCallId: string, onEvent: OnParamEvent) {\n this.messageId = `${toolCallId}-activity`;\n this.onEvent = onEvent;\n // The scanner skips bad characters and warns by itself, so no error\n // handler is needed here.\n this.scanner = new StreamingJsonScanner({\n onOpenObject: () => {\n this.depth++;\n },\n\n onKey: (key) => {\n if (this.depth === 1) {\n this.currentKey = key;\n this.initHtmlStreaming(key);\n }\n },\n\n onValue: (value) => {\n if (this.depth === 1 && this.currentKey) {\n if (this.currentArrayKey) {\n const strValue = String(value);\n if (this.currentArrayKey === \"jsExpressions\") {\n if (!this.params.jsExpressions) this.params.jsExpressions = [];\n this.params.jsExpressions.push(strValue);\n } else if (this.currentArrayKey === \"placeholderMessages\") {\n if (!this.params.placeholderMessages)\n this.params.placeholderMessages = [];\n this.params.placeholderMessages.push(strValue);\n }\n this.emitArrayItemDelta(this.currentArrayKey, strValue);\n } else if (this.streamingHtmlKey) {\n // The html string is complete. Emit the rest of it now, then htmlComplete.\n const fullHtml = value != null ? String(value) : \"\";\n this.params.html = fullHtml || undefined;\n this.emitPendingHtml(fullHtml);\n this.emitParamDelta(\"htmlComplete\", true);\n this.streamingHtmlKey = false;\n } else {\n this.setParam(this.currentKey, value);\n }\n }\n },\n\n onOpenArray: () => {\n if (this.depth === 1 && this.currentKey) {\n const key = this.currentKey;\n if (key === \"jsExpressions\" || key === \"placeholderMessages\") {\n this.currentArrayKey = key;\n if (key === \"jsExpressions\") this.params.jsExpressions = [];\n else this.params.placeholderMessages = [];\n // Emit a delta to create the array in the activity content.\n // Subsequent \"add\" ops with path \"/<key>/-\" append to this array.\n this.emitParamDelta(key, []);\n }\n }\n },\n\n onCloseArray: () => {\n if (this.depth === 1) {\n if (this.currentArrayKey === \"jsExpressions\") {\n this.emitParamDelta(\"jsExpressionsComplete\", true);\n }\n this.currentArrayKey = null;\n }\n },\n\n onCloseObject: () => {\n this.depth--;\n },\n });\n }\n\n write(chunk: string) {\n this.scanner.write(chunk);\n this.flushHtmlChunks();\n }\n\n private initHtmlStreaming(key: string) {\n if (key === \"html\") {\n this.streamingHtmlKey = true;\n this.htmlEmittedLength = 0;\n this.htmlArrayEmitted = false;\n }\n }\n\n /**\n * Emit the html read so far while the html string streams in.\n * Called after every write(). It reads only while the top-level `html`\n * value is being read, so a nested string is never emitted as html.\n */\n private flushHtmlChunks() {\n if (!this.streamingHtmlKey || this.depth !== 1) return;\n const partialHtml = this.scanner.partialString;\n if (partialHtml === undefined) return;\n if (partialHtml.length === this.htmlEmittedLength) return;\n\n this.emitPendingHtml(partialHtml);\n }\n\n /**\n * Emit accumulated html content since the last emission.\n * Called by flushHtmlChunks and directly when html completes.\n */\n private emitPendingHtml(html: string) {\n const newContent = html.slice(this.htmlEmittedLength);\n if (newContent.length === 0) return;\n\n if (!this.htmlArrayEmitted) {\n this.htmlArrayEmitted = true;\n this.emitParamDelta(\"html\", []);\n }\n this.emitArrayItemDelta(\"html\", newContent);\n this.htmlEmittedLength = html.length;\n }\n\n private setParam(key: string, value: JsonScalar) {\n switch (key) {\n case \"initialHeight\":\n this.params.initialHeight =\n typeof value === \"number\" ? value : undefined;\n if (this.snapshotEmitted) {\n // Snapshot already went out (another param parsed first) — deliver\n // the height as a delta instead.\n this.emitParamDelta(\"initialHeight\", this.params.initialHeight);\n } else {\n this.emitSnapshot();\n }\n break;\n case \"css\":\n this.params.css = value != null ? String(value) : undefined;\n this.emitParamDelta(\"css\", this.params.css);\n this.emitParamDelta(\"cssComplete\", true);\n break;\n case \"jsFunctions\":\n this.params.jsFunctions = value != null ? String(value) : undefined;\n this.emitParamDelta(\"jsFunctions\", this.params.jsFunctions);\n this.emitParamDelta(\"jsFunctionsComplete\", true);\n break;\n }\n }\n\n private emitSnapshot() {\n if (this.snapshotEmitted) return;\n this.snapshotEmitted = true;\n\n const event = {\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: this.messageId,\n activityType: ACTIVITY_TYPE,\n content: { initialHeight: this.params.initialHeight, generating: true },\n } satisfies ActivitySnapshotEventProps;\n this.onEvent(event);\n }\n\n private emitParamDelta(key: string, value: unknown) {\n // A JSON Patch \"add\" requires a value; emitting one without it (e.g. when\n // the LLM sends a null/empty jsFunctions or css) makes fast-json-patch\n // reject the whole patch client-side with OPERATION_VALUE_REQUIRED and\n // drops it. Skip the delta when there's nothing to add.\n if (value === undefined) return;\n // The activity message must exist before any delta can be applied —\n // the client silently drops ACTIVITY_DELTA events whose messageId has\n // no prior ACTIVITY_SNAPSHOT. The LLM controls the key order of the\n // streamed args, so the snapshot cannot wait for initialHeight.\n this.emitSnapshot();\n const event: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: this.messageId,\n activityType: ACTIVITY_TYPE,\n patch: [{ op: \"add\", path: `/${key}`, value }],\n };\n this.onEvent(event);\n }\n\n private emitArrayItemDelta(arrayKey: string, value: string) {\n this.emitSnapshot();\n const event: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: this.messageId,\n activityType: ACTIVITY_TYPE,\n patch: [{ op: \"add\", path: `/${arrayKey}/-`, value }],\n };\n this.onEvent(event);\n }\n}\n\n/**\n * Extract EventWithState type from Middleware.runNextWithState return type\n */\ntype ExtractObservableType<T> = T extends Observable<infer U> ? U : never;\ntype RunNextWithStateReturn = ReturnType<Middleware[\"runNextWithState\"]>;\ntype EventWithState = ExtractObservableType<RunNextWithStateReturn>;\n\nexport class OpenGenerativeUIMiddleware extends Middleware {\n run(input: RunAgentInput, next: AbstractAgent): Observable<BaseEvent> {\n return this.processStream(this.runNextWithState(input, next));\n }\n\n private processStream(\n source: Observable<EventWithState>,\n ): Observable<BaseEvent> {\n return new Observable<BaseEvent>((subscriber) => {\n let heldRunFinished: EventWithState | null = null;\n // Track active generateSandboxedUi tool call IDs → their streaming parser\n const activeParsers = new Map<string, ArgsParser>();\n // Hold genui tool call events until the first activity event is emitted\n const heldToolCallEvents = new Map<string, BaseEvent[]>();\n const flushedToolCalls = new Set<string>();\n\n const flushHeldEvents = (toolCallId: string) => {\n if (flushedToolCalls.has(toolCallId)) return;\n flushedToolCalls.add(toolCallId);\n const held = heldToolCallEvents.get(toolCallId);\n if (held) {\n for (const e of held) {\n subscriber.next(e);\n }\n heldToolCallEvents.delete(toolCallId);\n }\n };\n\n const subscription = source.subscribe({\n next: (eventWithState) => {\n const event = eventWithState.event;\n\n if (heldRunFinished) {\n subscriber.next(heldRunFinished.event);\n heldRunFinished = null;\n }\n\n if (event.type === EventType.RUN_FINISHED) {\n heldRunFinished = eventWithState;\n return;\n }\n\n // Hold TOOL_CALL_START for genui until the first activity event\n if (event.type === EventType.TOOL_CALL_START) {\n const startEvent = event as ToolCallStartEvent;\n if (startEvent.toolCallName === TOOL_NAME) {\n heldToolCallEvents.set(startEvent.toolCallId, [event]);\n activeParsers.set(\n startEvent.toolCallId,\n new ArgsParser(startEvent.toolCallId, (activityEvent) => {\n subscriber.next(activityEvent);\n flushHeldEvents(startEvent.toolCallId);\n }),\n );\n return;\n }\n }\n\n // Hold or emit TOOL_CALL_ARGS for genui tool calls\n if (event.type === EventType.TOOL_CALL_ARGS) {\n const argsEvent = event as ToolCallArgsEvent;\n const parser = activeParsers.get(argsEvent.toolCallId);\n if (parser) {\n if (!flushedToolCalls.has(argsEvent.toolCallId)) {\n heldToolCallEvents.get(argsEvent.toolCallId)!.push(event);\n } else {\n subscriber.next(event);\n }\n parser.write(argsEvent.delta);\n return;\n }\n }\n\n // Hold or emit TOOL_CALL_END for genui tool calls\n if (event.type === EventType.TOOL_CALL_END) {\n const endEvent = event as { toolCallId: string } & BaseEvent;\n const parser = activeParsers.get(endEvent.toolCallId);\n if (parser) {\n // Mark generation complete\n const completeEvent: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: parser.messageId,\n activityType: ACTIVITY_TYPE,\n patch: [{ op: \"add\", path: \"/generating\", value: false }],\n };\n subscriber.next(completeEvent);\n\n if (!flushedToolCalls.has(endEvent.toolCallId)) {\n heldToolCallEvents.get(endEvent.toolCallId)!.push(event);\n } else {\n subscriber.next(event);\n }\n return;\n }\n }\n\n subscriber.next(event);\n },\n error: (err) => {\n // Flush any held tool call events so downstream sees them before the error\n for (const [, events] of heldToolCallEvents) {\n for (const event of events) {\n subscriber.next(event);\n }\n }\n heldToolCallEvents.clear();\n\n if (heldRunFinished) {\n subscriber.next(heldRunFinished.event);\n heldRunFinished = null;\n }\n subscriber.error(err);\n },\n complete: () => {\n // Flush any remaining held tool call events (e.g. parser never emitted)\n heldToolCallEvents.forEach((_, toolCallId) => {\n flushHeldEvents(toolCallId);\n });\n\n if (heldRunFinished) {\n subscriber.next(heldRunFinished.event);\n heldRunFinished = null;\n }\n activeParsers.clear();\n subscriber.complete();\n },\n });\n\n return () => subscription.unsubscribe();\n });\n }\n}\n"],"mappings":";;;;;AAcA,MAAM,YAAY;AAClB,MAAM,gBAAgB;;;;;AAuBtB,IAAa,aAAb,MAAwB;CAiBtB,YAAY,YAAoB,SAAuB;oBAfnB;eACpB;yBACyB;yBACf;0BAIC;2BACC;0BACD;gBAEyB,EAAE;AAKpD,OAAK,YAAY,GAAG,WAAW;AAC/B,OAAK,UAAU;AAGf,OAAK,UAAU,IAAIA,oDAAqB;GACtC,oBAAoB;AAClB,SAAK;;GAGP,QAAQ,QAAQ;AACd,QAAI,KAAK,UAAU,GAAG;AACpB,UAAK,aAAa;AAClB,UAAK,kBAAkB,IAAI;;;GAI/B,UAAU,UAAU;AAClB,QAAI,KAAK,UAAU,KAAK,KAAK,WAC3B,KAAI,KAAK,iBAAiB;KACxB,MAAM,WAAW,OAAO,MAAM;AAC9B,SAAI,KAAK,oBAAoB,iBAAiB;AAC5C,UAAI,CAAC,KAAK,OAAO,cAAe,MAAK,OAAO,gBAAgB,EAAE;AAC9D,WAAK,OAAO,cAAc,KAAK,SAAS;gBAC/B,KAAK,oBAAoB,uBAAuB;AACzD,UAAI,CAAC,KAAK,OAAO,oBACf,MAAK,OAAO,sBAAsB,EAAE;AACtC,WAAK,OAAO,o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ime/event-transforms/open-generative-ui-middleware.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Parsed parameters from the generateSandboxedUi tool call.
|
|
7
|
+
*/
|
|
8
|
+
interface GenerateSandboxedUIParams {
|
|
9
|
+
initialHeight?: number;
|
|
10
|
+
placeholderMessages?: string[];
|
|
11
|
+
css?: string;
|
|
12
|
+
html?: string;
|
|
13
|
+
jsFunctions?: string;
|
|
14
|
+
jsExpressions?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Callback invoked by ArgsParser whenever a parameter (or array item) finishes parsing.
|
|
18
|
+
*/
|
|
19
|
+
type OnParamEvent = (event: BaseEvent) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Tracks incremental JSON parsing state for a single tool call's arguments.
|
|
22
|
+
* Emits activity events via the onEvent callback as parameters complete.
|
|
23
|
+
*/
|
|
24
|
+
declare class ArgsParser {
|
|
25
|
+
private readonly scanner;
|
|
26
|
+
private currentKey;
|
|
27
|
+
private depth;
|
|
28
|
+
private currentArrayKey;
|
|
29
|
+
private snapshotEmitted;
|
|
30
|
+
private streamingHtmlKey;
|
|
31
|
+
private htmlEmittedLength;
|
|
32
|
+
private htmlArrayEmitted;
|
|
33
|
+
readonly params: GenerateSandboxedUIParams;
|
|
34
|
+
readonly messageId: string;
|
|
35
|
+
private readonly onEvent;
|
|
36
|
+
constructor(toolCallId: string, onEvent: OnParamEvent);
|
|
37
|
+
write(chunk: string): void;
|
|
38
|
+
private initHtmlStreaming;
|
|
39
|
+
/**
|
|
40
|
+
* Emit the html read so far while the html string streams in.
|
|
41
|
+
* Called after every write(). It reads only while the top-level `html`
|
|
42
|
+
* value is being read, so a nested string is never emitted as html.
|
|
43
|
+
*/
|
|
44
|
+
private flushHtmlChunks;
|
|
45
|
+
/**
|
|
46
|
+
* Emit accumulated html content since the last emission.
|
|
47
|
+
* Called by flushHtmlChunks and directly when html completes.
|
|
48
|
+
*/
|
|
49
|
+
private emitPendingHtml;
|
|
50
|
+
private setParam;
|
|
51
|
+
private emitSnapshot;
|
|
52
|
+
private emitParamDelta;
|
|
53
|
+
private emitArrayItemDelta;
|
|
54
|
+
}
|
|
55
|
+
declare class OpenGenerativeUIMiddleware extends Middleware {
|
|
56
|
+
run(input: RunAgentInput, next: AbstractAgent): Observable<BaseEvent>;
|
|
57
|
+
private processStream;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware };
|
|
61
|
+
//# sourceMappingURL=open-generative-ui-middleware.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-generative-ui-middleware.d.cts","names":[],"sources":["../../../src/runtime/event-transforms/open-generative-ui-middleware.ts"],"mappings":";;;;;AAoBA;;UAAiB,yBAAA;EACf,aAAA;EACA,mBAAA;EACA,GAAA;EACA,IAAA;EACA,WAAA;EACA,aAAA;AAAA;;;AAMF;KAAY,YAAA,IAAgB,KAAA,EAAO,SAAA;;;;AAMnC;cAAa,UAAA;EAAA,iBACM,OAAA;EAAA,QACT,UAAA;EAAA,QACA,KAAA;EAAA,QACA,eAAA;EAAA,QACA,eAAA;EAAA,QAIA,gBAAA;EAAA,QACA,iBAAA;EAAA,QACA,gBAAA;EAAA,SAEQ,MAAA,EAAQ,yBAAA;EAAA,SACR,SAAA;EAAA,iBACC,OAAA;cAEL,UAAA,UAAoB,OAAA,EAAS,YAAA;EAwEzC,KAAA,CAAM,KAAA;EAAA,QAKE,iBAAA;;;;;;UAaA,eAAA;EAbA;;;;EAAA,QA0BA,eAAA;EAAA,QAYA,QAAA;EAAA,QA0BA,YAAA;EAAA,QAaA,cAAA;EAAA,QAoBA,kBAAA;AAAA;AAAA,cAmBG,0BAAA,SAAmC,UAAA;EAC9C,GAAA,CAAI,KAAA,EAAO,aAAA,EAAe,IAAA,EAAM,aAAA,GAAgB,UAAA,CAAW,SAAA;EAAA,QAInD,aAAA;AAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { AbstractAgent, BaseEvent, Middleware, RunAgentInput } from "@ag-ui/client";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/event-transforms/open-generative-ui-middleware.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Parsed parameters from the generateSandboxedUi tool call.
|
|
7
|
+
*/
|
|
8
|
+
interface GenerateSandboxedUIParams {
|
|
9
|
+
initialHeight?: number;
|
|
10
|
+
placeholderMessages?: string[];
|
|
11
|
+
css?: string;
|
|
12
|
+
html?: string;
|
|
13
|
+
jsFunctions?: string;
|
|
14
|
+
jsExpressions?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Callback invoked by ArgsParser whenever a parameter (or array item) finishes parsing.
|
|
18
|
+
*/
|
|
19
|
+
type OnParamEvent = (event: BaseEvent) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Tracks incremental JSON parsing state for a single tool call's arguments.
|
|
22
|
+
* Emits activity events via the onEvent callback as parameters complete.
|
|
23
|
+
*/
|
|
24
|
+
declare class ArgsParser {
|
|
25
|
+
private readonly scanner;
|
|
26
|
+
private currentKey;
|
|
27
|
+
private depth;
|
|
28
|
+
private currentArrayKey;
|
|
29
|
+
private snapshotEmitted;
|
|
30
|
+
private streamingHtmlKey;
|
|
31
|
+
private htmlEmittedLength;
|
|
32
|
+
private htmlArrayEmitted;
|
|
33
|
+
readonly params: GenerateSandboxedUIParams;
|
|
34
|
+
readonly messageId: string;
|
|
35
|
+
private readonly onEvent;
|
|
36
|
+
constructor(toolCallId: string, onEvent: OnParamEvent);
|
|
37
|
+
write(chunk: string): void;
|
|
38
|
+
private initHtmlStreaming;
|
|
39
|
+
/**
|
|
40
|
+
* Emit the html read so far while the html string streams in.
|
|
41
|
+
* Called after every write(). It reads only while the top-level `html`
|
|
42
|
+
* value is being read, so a nested string is never emitted as html.
|
|
43
|
+
*/
|
|
44
|
+
private flushHtmlChunks;
|
|
45
|
+
/**
|
|
46
|
+
* Emit accumulated html content since the last emission.
|
|
47
|
+
* Called by flushHtmlChunks and directly when html completes.
|
|
48
|
+
*/
|
|
49
|
+
private emitPendingHtml;
|
|
50
|
+
private setParam;
|
|
51
|
+
private emitSnapshot;
|
|
52
|
+
private emitParamDelta;
|
|
53
|
+
private emitArrayItemDelta;
|
|
54
|
+
}
|
|
55
|
+
declare class OpenGenerativeUIMiddleware extends Middleware {
|
|
56
|
+
run(input: RunAgentInput, next: AbstractAgent): Observable<BaseEvent>;
|
|
57
|
+
private processStream;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware };
|
|
61
|
+
//# sourceMappingURL=open-generative-ui-middleware.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-generative-ui-middleware.d.mts","names":[],"sources":["../../../src/runtime/event-transforms/open-generative-ui-middleware.ts"],"mappings":";;;;;AAoBA;;UAAiB,yBAAA;EACf,aAAA;EACA,mBAAA;EACA,GAAA;EACA,IAAA;EACA,WAAA;EACA,aAAA;AAAA;;;AAMF;KAAY,YAAA,IAAgB,KAAA,EAAO,SAAA;;;;AAMnC;cAAa,UAAA;EAAA,iBACM,OAAA;EAAA,QACT,UAAA;EAAA,QACA,KAAA;EAAA,QACA,eAAA;EAAA,QACA,eAAA;EAAA,QAIA,gBAAA;EAAA,QACA,iBAAA;EAAA,QACA,gBAAA;EAAA,SAEQ,MAAA,EAAQ,yBAAA;EAAA,SACR,SAAA;EAAA,iBACC,OAAA;cAEL,UAAA,UAAoB,OAAA,EAAS,YAAA;EAwEzC,KAAA,CAAM,KAAA;EAAA,QAKE,iBAAA;;;;;;UAaA,eAAA;EAbA;;;;EAAA,QA0BA,eAAA;EAAA,QAYA,QAAA;EAAA,QA0BA,YAAA;EAAA,QAaA,cAAA;EAAA,QAoBA,kBAAA;AAAA;AAAA,cAmBG,0BAAA,SAAmC,UAAA;EAC9C,GAAA,CAAI,KAAA,EAAO,aAAA,EAAe,IAAA,EAAM,aAAA,GAAgB,UAAA,CAAW,SAAA;EAAA,QAInD,aAAA;AAAA"}
|