@ggui-ai/protocol 0.2.0-alpha.4 → 0.3.0-rc.0

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.
Files changed (197) hide show
  1. package/README.md +16 -16
  2. package/dist/envelope-adapters.d.ts +6 -5
  3. package/dist/envelope-adapters.d.ts.map +1 -1
  4. package/dist/envelope-adapters.js +3 -3
  5. package/dist/envelopes/builders.d.ts +6 -32
  6. package/dist/envelopes/builders.d.ts.map +1 -1
  7. package/dist/envelopes/builders.js +3 -25
  8. package/dist/errors/version-mismatch.d.ts +1 -1
  9. package/dist/errors/version-mismatch.js +1 -1
  10. package/dist/gadgets/resolve-app-gadgets.d.ts +10 -0
  11. package/dist/gadgets/resolve-app-gadgets.d.ts.map +1 -0
  12. package/dist/gadgets/resolve-app-gadgets.js +19 -0
  13. package/dist/gadgets/resolve-contract-gadgets.d.ts +6 -6
  14. package/dist/gadgets/resolve-contract-gadgets.js +5 -5
  15. package/dist/gadgets/stdlib-gadgets.d.ts +1 -1
  16. package/dist/gadgets/stdlib-gadgets.d.ts.map +1 -1
  17. package/dist/gadgets/stdlib-gadgets.js +43 -22
  18. package/dist/iframe-bridge.d.ts +4 -43
  19. package/dist/iframe-bridge.d.ts.map +1 -1
  20. package/dist/iframe-bridge.js +4 -141
  21. package/dist/index.d.ts +60 -62
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +66 -61
  24. package/dist/integrations/mcp-apps.d.ts +83 -38
  25. package/dist/integrations/mcp-apps.d.ts.map +1 -1
  26. package/dist/integrations/mcp-apps.js +98 -52
  27. package/dist/recommended-prompts.d.ts +1 -1
  28. package/dist/recommended-prompts.js +1 -1
  29. package/dist/registry/blueprint-key.d.ts +3 -0
  30. package/dist/registry/blueprint-key.d.ts.map +1 -1
  31. package/dist/registry/blueprint-key.js +9 -0
  32. package/dist/registry/blueprint-stamp.d.ts +12 -0
  33. package/dist/registry/blueprint-stamp.d.ts.map +1 -0
  34. package/dist/registry/blueprint-stamp.js +12 -0
  35. package/dist/registry/canonicalize-contract.d.ts +31 -2
  36. package/dist/registry/canonicalize-contract.d.ts.map +1 -1
  37. package/dist/registry/canonicalize-contract.js +125 -13
  38. package/dist/registry/portable-blueprint.d.ts +64 -0
  39. package/dist/registry/portable-blueprint.d.ts.map +1 -0
  40. package/dist/registry/portable-blueprint.js +103 -0
  41. package/dist/registry/summarize-contract.d.ts +7 -2
  42. package/dist/registry/summarize-contract.d.ts.map +1 -1
  43. package/dist/registry/summarize-contract.js +12 -3
  44. package/dist/registry/variant-key.d.ts +17 -0
  45. package/dist/registry/variant-key.d.ts.map +1 -0
  46. package/dist/registry/variant-key.js +22 -0
  47. package/dist/schema-learning/derive-contract.d.ts +2 -2
  48. package/dist/schema-learning/derive-contract.js +2 -2
  49. package/dist/schema-learning/merge.d.ts.map +1 -1
  50. package/dist/schema-learning/merge.js +3 -2
  51. package/dist/schemas/app-theme.d.ts +38 -0
  52. package/dist/schemas/app-theme.d.ts.map +1 -0
  53. package/dist/schemas/app-theme.js +43 -0
  54. package/dist/schemas/blueprint.d.ts +30 -11
  55. package/dist/schemas/blueprint.d.ts.map +1 -1
  56. package/dist/schemas/blueprint.js +62 -26
  57. package/dist/schemas/data-contract.d.ts +28 -30
  58. package/dist/schemas/data-contract.d.ts.map +1 -1
  59. package/dist/schemas/data-contract.js +26 -26
  60. package/dist/schemas/handshake-suggestion.d.ts +2 -4
  61. package/dist/schemas/handshake-suggestion.d.ts.map +1 -1
  62. package/dist/schemas/handshake-suggestion.js +5 -14
  63. package/dist/schemas/mcp.d.ts +240 -58
  64. package/dist/schemas/mcp.d.ts.map +1 -1
  65. package/dist/schemas/mcp.js +285 -93
  66. package/dist/schemas/ops-blueprint.d.ts +12 -12
  67. package/dist/schemas/ops-blueprint.d.ts.map +1 -1
  68. package/dist/schemas/ops-blueprint.js +14 -24
  69. package/dist/screen-blueprints/define.d.ts +2 -2
  70. package/dist/screen-blueprints/match.d.ts +12 -7
  71. package/dist/screen-blueprints/match.d.ts.map +1 -1
  72. package/dist/screen-blueprints/match.js +7 -5
  73. package/dist/screen-blueprints/types.d.ts +14 -18
  74. package/dist/screen-blueprints/types.d.ts.map +1 -1
  75. package/dist/transport/websocket.d.ts +5 -26
  76. package/dist/transport/websocket.d.ts.map +1 -1
  77. package/dist/types/app-config.d.ts +0 -1
  78. package/dist/types/app-config.d.ts.map +1 -1
  79. package/dist/types/auth.d.ts +1 -46
  80. package/dist/types/auth.d.ts.map +1 -1
  81. package/dist/types/blueprint-source.d.ts +123 -0
  82. package/dist/types/blueprint-source.d.ts.map +1 -0
  83. package/dist/types/blueprint-source.js +126 -0
  84. package/dist/types/blueprint.d.ts +25 -18
  85. package/dist/types/blueprint.d.ts.map +1 -1
  86. package/dist/types/contract-inference.d.ts +2 -43
  87. package/dist/types/contract-inference.d.ts.map +1 -1
  88. package/dist/types/data-contract.d.ts +59 -344
  89. package/dist/types/data-contract.d.ts.map +1 -1
  90. package/dist/types/data-contract.js +5 -12
  91. package/dist/types/events.d.ts +31 -69
  92. package/dist/types/events.d.ts.map +1 -1
  93. package/dist/types/{render-event.d.ts → ggui-session-event.d.ts} +15 -15
  94. package/dist/types/ggui-session-event.d.ts.map +1 -0
  95. package/dist/types/{render-event.js → ggui-session-event.js} +5 -5
  96. package/dist/types/handshake-suggestion.d.ts +49 -35
  97. package/dist/types/handshake-suggestion.d.ts.map +1 -1
  98. package/dist/types/host-context.d.ts +8 -8
  99. package/dist/types/host-context.d.ts.map +1 -1
  100. package/dist/types/host-context.js +5 -5
  101. package/dist/types/invoke.d.ts +1 -13
  102. package/dist/types/invoke.d.ts.map +1 -1
  103. package/dist/types/{canvas-lifecycle.d.ts → lifecycle.d.ts} +35 -37
  104. package/dist/types/lifecycle.d.ts.map +1 -0
  105. package/dist/types/{canvas-lifecycle.js → lifecycle.js} +12 -14
  106. package/dist/types/live-channel.d.ts +48 -104
  107. package/dist/types/live-channel.d.ts.map +1 -1
  108. package/dist/types/llm.d.ts +13 -24
  109. package/dist/types/llm.d.ts.map +1 -1
  110. package/dist/types/llm.js +23 -53
  111. package/dist/types/mcp.d.ts +55 -176
  112. package/dist/types/mcp.d.ts.map +1 -1
  113. package/dist/types/mcp.js +2 -2
  114. package/dist/types/oauth-user-id.d.ts +12 -0
  115. package/dist/types/oauth-user-id.d.ts.map +1 -0
  116. package/dist/types/oauth-user-id.js +10 -0
  117. package/dist/types/portable-blueprint.d.ts +53 -0
  118. package/dist/types/portable-blueprint.d.ts.map +1 -0
  119. package/dist/types/portable-blueprint.js +8 -0
  120. package/dist/types/{session.d.ts → render.d.ts} +51 -53
  121. package/dist/types/render.d.ts.map +1 -0
  122. package/dist/types/thread.d.ts.map +1 -1
  123. package/dist/types/thread.js +3 -3
  124. package/dist/types/ui-generator.d.ts +5 -46
  125. package/dist/types/ui-generator.d.ts.map +1 -1
  126. package/dist/types/ui-generator.js +1 -53
  127. package/dist/validation/ajv-runtime.d.ts +3 -3
  128. package/dist/validation/ajv-runtime.d.ts.map +1 -1
  129. package/dist/validation/ajv-runtime.js +6 -5
  130. package/dist/validation/contract-validator.d.ts +23 -22
  131. package/dist/validation/contract-validator.d.ts.map +1 -1
  132. package/dist/validation/contract-validator.js +28 -26
  133. package/dist/validation/cross-references.d.ts +3 -3
  134. package/dist/validation/cross-references.js +3 -3
  135. package/dist/validation/hygiene-rules.d.ts +9 -9
  136. package/dist/validation/hygiene-rules.js +13 -13
  137. package/dist/validation/is-record.d.ts +17 -0
  138. package/dist/validation/is-record.d.ts.map +1 -0
  139. package/dist/validation/is-record.js +18 -0
  140. package/dist/validation/lint-contract.d.ts +1 -1
  141. package/dist/validation/lint-contract.js +3 -3
  142. package/dist/validation/name-invariants.d.ts +4 -4
  143. package/dist/validation/name-invariants.js +4 -4
  144. package/dist/validation/reserved-channels.d.ts +43 -46
  145. package/dist/validation/reserved-channels.d.ts.map +1 -1
  146. package/dist/validation/reserved-channels.js +14 -177
  147. package/dist/validation/resolve-stream-channel.d.ts +3 -9
  148. package/dist/validation/resolve-stream-channel.d.ts.map +1 -1
  149. package/dist/validation/resolve-stream-channel.js +3 -4
  150. package/dist/validation/sanitize-error.d.ts +10 -9
  151. package/dist/validation/sanitize-error.d.ts.map +1 -1
  152. package/dist/validation/sanitize-error.js +19 -18
  153. package/dist/validation/schema-compat-invariants.d.ts +1 -1
  154. package/dist/validation/schema-compat-invariants.js +3 -3
  155. package/dist/validation/schema-meta-validation.d.ts +4 -4
  156. package/dist/validation/schema-meta-validation.d.ts.map +1 -1
  157. package/dist/validation/schema-meta-validation.js +7 -9
  158. package/dist/validation/schema-subset.d.ts +9 -8
  159. package/dist/validation/schema-subset.d.ts.map +1 -1
  160. package/dist/validation/ui-security.d.ts +0 -17
  161. package/dist/validation/ui-security.d.ts.map +1 -1
  162. package/dist/validation/ui-security.js +17 -22
  163. package/dist/validation/zod-to-json-schema.d.ts +1 -1
  164. package/dist/validation/zod-to-json-schema.d.ts.map +1 -1
  165. package/dist/validation/zod-to-json-schema.js +4 -3
  166. package/dist/version.d.ts +783 -9
  167. package/dist/version.d.ts.map +1 -1
  168. package/dist/version.js +782 -8
  169. package/package.json +2 -2
  170. package/dist/bridge/invoke-agent.d.ts +0 -65
  171. package/dist/bridge/invoke-agent.d.ts.map +0 -1
  172. package/dist/bridge/invoke-agent.js +0 -113
  173. package/dist/stream/stream-parser.d.ts +0 -62
  174. package/dist/stream/stream-parser.d.ts.map +0 -1
  175. package/dist/stream/stream-parser.js +0 -199
  176. package/dist/types/canvas-lifecycle.d.ts.map +0 -1
  177. package/dist/types/credential.d.ts +0 -41
  178. package/dist/types/credential.d.ts.map +0 -1
  179. package/dist/types/credential.js +0 -32
  180. package/dist/types/data-bindings.d.ts +0 -322
  181. package/dist/types/data-bindings.d.ts.map +0 -1
  182. package/dist/types/data-bindings.js +0 -29
  183. package/dist/types/feedback.d.ts +0 -22
  184. package/dist/types/feedback.d.ts.map +0 -1
  185. package/dist/types/feedback.js +0 -7
  186. package/dist/types/mcp-proxy.d.ts +0 -67
  187. package/dist/types/mcp-proxy.d.ts.map +0 -1
  188. package/dist/types/mcp-proxy.js +0 -46
  189. package/dist/types/openrouter-models.d.ts +0 -23
  190. package/dist/types/openrouter-models.d.ts.map +0 -1
  191. package/dist/types/openrouter-models.js +0 -4843
  192. package/dist/types/region.d.ts +0 -26
  193. package/dist/types/region.d.ts.map +0 -1
  194. package/dist/types/region.js +0 -36
  195. package/dist/types/render-event.d.ts.map +0 -1
  196. package/dist/types/session.d.ts.map +0 -1
  197. /package/dist/types/{session.js → render.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ggui-ai/protocol",
3
- "version": "0.2.0-alpha.4",
3
+ "version": "0.3.0-rc.0",
4
4
  "description": "ggui protocol types — events, renders, WebSocket, MCP, LLM models",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -104,7 +104,7 @@
104
104
  },
105
105
  "author": "ggui contributors <hello@ggui.ai>",
106
106
  "scripts": {
107
- "build": "tsc && node ../scripts/fix-esm-imports.mjs dist",
107
+ "build": "rm -rf dist && tsc && node ../scripts/fix-esm-imports.mjs dist",
108
108
  "dev": "tsc --watch",
109
109
  "typecheck": "tsc --noEmit",
110
110
  "sync-check": "tsx src/schemas/sync-check.ts",
@@ -1,65 +0,0 @@
1
- /**
2
- * Agent invocation helper for the bridge agent pattern.
3
- *
4
- * Cloud-provider agnostic — uses standard fetch API. Can be used by any
5
- * platform implementation (serverless function, self-hosted server, etc.) that needs
6
- * to forward messages to an agent's HTTP endpoint.
7
- *
8
- * Handles both JSON and SSE streaming responses using stream-parser.
9
- */
10
- import type { InterfaceContext } from '../types/interface-context';
11
- import type { ConversationTurn } from '../types/session';
12
- export interface InvokeAgentOptions {
13
- /** The agent's HTTP endpoint URL */
14
- connectorEndpointUrl: string;
15
- /** Conversation envelope id (omit for 'start' flow — agent mints one) */
16
- hostSessionId?: string;
17
- /** Invocation type: 'start' begins a fresh conversation, 'message' continues one */
18
- type: 'start' | 'message';
19
- /** User message text */
20
- message?: string;
21
- /** App ID to include in the request */
22
- appId: string;
23
- /** Client interface context (device, viewport, shell type) */
24
- interfaceContext?: InterfaceContext;
25
- /** Conversation history for multi-turn context */
26
- conversationHistory?: ConversationTurn[];
27
- /** Callback to forward streaming text chunks to the user */
28
- onStreamChunk?: (text: string) => Promise<void>;
29
- /** Callback when the stream is done */
30
- onStreamDone?: () => Promise<void>;
31
- /** Callback when the agent returns a hostSessionId (start flow, SSE) */
32
- onHostSessionId?: (hostSessionId: string) => Promise<void>;
33
- /** Callback for structured agent events (stream, push, etc.) from the events array */
34
- onAgentEvent?: (event: {
35
- type: string;
36
- payload: unknown;
37
- }) => Promise<void>;
38
- /** Request timeout in milliseconds (default: 90000) */
39
- timeoutMs?: number;
40
- }
41
- export interface InvokeAgentResult {
42
- /** Conversation envelope id returned by the agent (start flow) */
43
- hostSessionId?: string;
44
- /** Full text response (JSON responses only — streaming uses callbacks) */
45
- text?: string;
46
- /** Whether the response was streamed via SSE */
47
- streamed: boolean;
48
- /** Outcome status */
49
- status: 'ok' | 'error';
50
- /** Error message if status is 'error' */
51
- error?: string;
52
- }
53
- /**
54
- * Invoke an agent's HTTP endpoint and handle the response.
55
- *
56
- * Supports two response formats:
57
- * 1. JSON — returns the parsed body as InvokeAgentResult
58
- * 2. SSE stream — forwards chunks via callbacks, returns when stream ends
59
- *
60
- * The request body shape follows the ggui bridge protocol:
61
- * - start: { type: 'start', message, appId, interfaceContext }
62
- * - message: { type: 'message', hostSessionId, appId, message, conversationHistory, interfaceContext }
63
- */
64
- export declare function invokeAgentEndpoint(options: InvokeAgentOptions): Promise<InvokeAgentResult>;
65
- //# sourceMappingURL=invoke-agent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"invoke-agent.d.ts","sourceRoot":"","sources":["../../src/bridge/invoke-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAgBzD,MAAM,WAAW,kBAAkB;IACjC,oCAAoC;IACpC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,yEAAyE;IACzE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oFAAoF;IACpF,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,wBAAwB;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,kDAAkD;IAClD,mBAAmB,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACzC,4DAA4D;IAC5D,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,wEAAwE;IACxE,eAAe,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,sFAAsF;IACtF,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5E,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,kEAAkE;IAClE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,QAAQ,EAAE,OAAO,CAAC;IAClB,qBAAqB;IACrB,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC;IACvB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CA4G5B"}
@@ -1,113 +0,0 @@
1
- import { z } from 'zod';
2
- import { isStreamingContentType } from '../stream/stream-parser.js';
3
- /** Schema for agent HTTP response data — validates untrusted external input. */
4
- const agentResponseSchema = z.object({
5
- hostSessionId: z.string().optional(),
6
- text: z.string().optional(),
7
- events: z.array(z.object({
8
- type: z.string(),
9
- payload: z.unknown(),
10
- }).passthrough()).optional(),
11
- }).passthrough();
12
- // ── Implementation ──
13
- /**
14
- * Invoke an agent's HTTP endpoint and handle the response.
15
- *
16
- * Supports two response formats:
17
- * 1. JSON — returns the parsed body as InvokeAgentResult
18
- * 2. SSE stream — forwards chunks via callbacks, returns when stream ends
19
- *
20
- * The request body shape follows the ggui bridge protocol:
21
- * - start: { type: 'start', message, appId, interfaceContext }
22
- * - message: { type: 'message', hostSessionId, appId, message, conversationHistory, interfaceContext }
23
- */
24
- export async function invokeAgentEndpoint(options) {
25
- const { connectorEndpointUrl, type, appId, hostSessionId, message, interfaceContext, conversationHistory, onStreamChunk, onStreamDone, onHostSessionId, timeoutMs = 90_000, } = options;
26
- // Build request body based on invocation type
27
- const body = { type, appId };
28
- if (type === 'start') {
29
- if (hostSessionId)
30
- body.hostSessionId = hostSessionId;
31
- body.message = message || 'Start a new session';
32
- if (interfaceContext)
33
- body.interfaceContext = interfaceContext;
34
- }
35
- else {
36
- body.hostSessionId = hostSessionId;
37
- body.message = message;
38
- if (interfaceContext)
39
- body.interfaceContext = interfaceContext;
40
- if (conversationHistory && conversationHistory.length > 0) {
41
- body.conversationHistory = conversationHistory;
42
- }
43
- }
44
- // Build headers
45
- const headers = {
46
- 'Content-Type': 'application/json',
47
- 'X-Ggui-App-Id': appId,
48
- };
49
- if (hostSessionId) {
50
- headers['X-Ggui-Host-Session-Id'] = hostSessionId;
51
- }
52
- // POST to agent endpoint
53
- let response;
54
- try {
55
- response = await fetch(connectorEndpointUrl, {
56
- method: 'POST',
57
- headers,
58
- body: JSON.stringify(body),
59
- signal: AbortSignal.timeout(timeoutMs),
60
- });
61
- }
62
- catch (err) {
63
- const errMsg = err instanceof Error ? err.message : 'Agent invocation failed';
64
- return { status: 'error', error: errMsg, streamed: false };
65
- }
66
- if (!response.ok) {
67
- return {
68
- status: 'error',
69
- error: `Agent returned ${response.status}`,
70
- streamed: false,
71
- };
72
- }
73
- // Determine response format
74
- const contentType = response.headers.get('content-type') || '';
75
- const transferEncoding = response.headers.get('transfer-encoding') || '';
76
- // Read the full response body (SSE or JSON)
77
- const responseText = await response.text();
78
- // Parse the response — handle SSE format (strip `data: ` prefix)
79
- let agentData;
80
- try {
81
- // SSE responses have `data: {...}` lines
82
- const lines = responseText.split('\n').filter(l => l.startsWith('data: '));
83
- const raw = lines.length > 0
84
- ? JSON.parse(lines[lines.length - 1].slice(6).trim())
85
- : JSON.parse(responseText);
86
- agentData = agentResponseSchema.parse(raw);
87
- }
88
- catch {
89
- // Couldn't parse or validate — forward raw text
90
- await onStreamChunk?.(responseText);
91
- await onStreamDone?.();
92
- return { status: 'ok', streamed: true };
93
- }
94
- // Extract hostSessionId
95
- if (agentData.hostSessionId) {
96
- await onHostSessionId?.(agentData.hostSessionId);
97
- }
98
- // Forward structured agent events
99
- if (agentData.events && options.onAgentEvent) {
100
- for (const event of agentData.events) {
101
- await options.onAgentEvent(event);
102
- }
103
- }
104
- // Extract text for conversation history
105
- const resultText = agentData.text;
106
- await onStreamDone?.();
107
- return {
108
- hostSessionId: agentData.hostSessionId,
109
- text: resultText,
110
- status: 'ok',
111
- streamed: isStreamingContentType(contentType, transferEncoding),
112
- };
113
- }
@@ -1,62 +0,0 @@
1
- /**
2
- * Universal stream parser for agent responses.
3
- *
4
- * Extracts text from any LLM provider's streaming format (Anthropic, OpenAI,
5
- * Gemini, Cohere, Mistral, etc.) without hardcoding provider schemas.
6
- * Uses depth-first search on well-known field names and container structures.
7
- *
8
- * Decoupled from any transport (WebSocket, HTTP, etc.) — callers provide
9
- * callbacks for chunk delivery.
10
- */
11
- /**
12
- * Detect whether a response should be treated as a stream based on headers.
13
- * Accepts raw header strings so callers aren't coupled to the fetch API.
14
- */
15
- export declare function isStreamingContentType(contentType: string, transferEncoding?: string): boolean;
16
- /**
17
- * Depth-first search for a text string in a JSON structure.
18
- *
19
- * Search strategy:
20
- * 1. Check TEXT_FIELDS at current level (string values only)
21
- * 2. Recurse into CONTAINER_FIELDS
22
- *
23
- * Works with any provider because it searches by field-name patterns,
24
- * not by provider-specific schemas.
25
- */
26
- export declare function deepFindText(obj: unknown, depth?: number): string;
27
- /**
28
- * Detect if a streaming JSON event signals end-of-stream.
29
- *
30
- * Recognized signals:
31
- * - type: "done" / "message_stop"
32
- * - choices[0].finish_reason !== null
33
- * - (HTTP stream close is handled by the reader, not here)
34
- */
35
- export declare function isStreamDone(data: Record<string, unknown>): boolean;
36
- /**
37
- * Extract hostSessionId (conversation envelope id) from a streaming event.
38
- * Checks for a top-level `hostSessionId` string — no envelope format required.
39
- */
40
- export declare function extractHostSessionId(data: Record<string, unknown>): string | undefined;
41
- /**
42
- * Callbacks for stream consumers. Transport-agnostic — works with WebSocket,
43
- * HTTP response streaming, file output, or anything else.
44
- */
45
- export interface StreamCallbacks {
46
- onChunk: (text: string) => Promise<void>;
47
- onDone: () => Promise<void>;
48
- onHostSessionId?: (hostSessionId: string) => Promise<void>;
49
- }
50
- /**
51
- * Read a streaming HTTP response and invoke callbacks for each text chunk.
52
- *
53
- * Supports three wire formats:
54
- * 1. text/event-stream (SSE) — parses `data:` lines
55
- * 2. application/x-ndjson — one JSON object per line
56
- * 3. Any other — forwards raw text chunks
57
- *
58
- * JSON events (SSE and NDJSON) are parsed with deepFindText for universal
59
- * text extraction. Non-JSON content is forwarded as raw text.
60
- */
61
- export declare function readStream(body: ReadableStream<Uint8Array>, contentType: string, callbacks: StreamCallbacks): Promise<void>;
62
- //# sourceMappingURL=stream-parser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream-parser.d.ts","sourceRoot":"","sources":["../../src/stream/stream-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,MAAM,EACnB,gBAAgB,CAAC,EAAE,MAAM,GACxB,OAAO,CAKT;AAUD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,MAAM,CA0B5D;AAID;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAUnE;AAID;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,SAAS,CAKtF;AAID;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,eAAe,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5D;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,eAAe,GACzB,OAAO,CAAC,IAAI,CAAC,CAkFf"}
@@ -1,199 +0,0 @@
1
- /**
2
- * Universal stream parser for agent responses.
3
- *
4
- * Extracts text from any LLM provider's streaming format (Anthropic, OpenAI,
5
- * Gemini, Cohere, Mistral, etc.) without hardcoding provider schemas.
6
- * Uses depth-first search on well-known field names and container structures.
7
- *
8
- * Decoupled from any transport (WebSocket, HTTP, etc.) — callers provide
9
- * callbacks for chunk delivery.
10
- */
11
- // ── Detection ──
12
- /**
13
- * Detect whether a response should be treated as a stream based on headers.
14
- * Accepts raw header strings so callers aren't coupled to the fetch API.
15
- */
16
- export function isStreamingContentType(contentType, transferEncoding) {
17
- if (contentType.includes('text/event-stream'))
18
- return true;
19
- if (contentType.includes('application/x-ndjson'))
20
- return true;
21
- if (contentType.includes('text/plain') && transferEncoding?.includes('chunked'))
22
- return true;
23
- return false;
24
- }
25
- // ── Text extraction ──
26
- /** Well-known field names that carry streaming text across LLM providers. */
27
- const TEXT_FIELDS = ['text', 'content', 'chunk', 'message', 'output', 'response'];
28
- /** Well-known container fields that wrap text in nested structures. */
29
- const CONTAINER_FIELDS = ['delta', 'choices', 'candidates', 'parts', 'content_block', 'data', 'body'];
30
- /**
31
- * Depth-first search for a text string in a JSON structure.
32
- *
33
- * Search strategy:
34
- * 1. Check TEXT_FIELDS at current level (string values only)
35
- * 2. Recurse into CONTAINER_FIELDS
36
- *
37
- * Works with any provider because it searches by field-name patterns,
38
- * not by provider-specific schemas.
39
- */
40
- export function deepFindText(obj, depth = 0) {
41
- if (depth > 6)
42
- return '';
43
- if (!obj || typeof obj !== 'object')
44
- return '';
45
- const record = obj;
46
- for (const key of TEXT_FIELDS) {
47
- const val = record[key];
48
- if (typeof val === 'string' && val.length > 0)
49
- return val;
50
- }
51
- for (const key of CONTAINER_FIELDS) {
52
- if (!(key in record))
53
- continue;
54
- const val = record[key];
55
- if (Array.isArray(val)) {
56
- for (const item of val) {
57
- const found = deepFindText(item, depth + 1);
58
- if (found)
59
- return found;
60
- }
61
- }
62
- else {
63
- const found = deepFindText(val, depth + 1);
64
- if (found)
65
- return found;
66
- }
67
- }
68
- return '';
69
- }
70
- // ── Done detection ──
71
- /**
72
- * Detect if a streaming JSON event signals end-of-stream.
73
- *
74
- * Recognized signals:
75
- * - type: "done" / "message_stop"
76
- * - choices[0].finish_reason !== null
77
- * - (HTTP stream close is handled by the reader, not here)
78
- */
79
- export function isStreamDone(data) {
80
- const t = data.type;
81
- if (t === 'done' || t === 'message_stop')
82
- return true;
83
- if (Array.isArray(data.choices)) {
84
- const first = data.choices[0];
85
- if (first?.finish_reason != null)
86
- return true;
87
- }
88
- return false;
89
- }
90
- // ── HostSessionId extraction ──
91
- /**
92
- * Extract hostSessionId (conversation envelope id) from a streaming event.
93
- * Checks for a top-level `hostSessionId` string — no envelope format required.
94
- */
95
- export function extractHostSessionId(data) {
96
- if (typeof data.hostSessionId === 'string' && data.hostSessionId) {
97
- return data.hostSessionId;
98
- }
99
- return undefined;
100
- }
101
- /**
102
- * Read a streaming HTTP response and invoke callbacks for each text chunk.
103
- *
104
- * Supports three wire formats:
105
- * 1. text/event-stream (SSE) — parses `data:` lines
106
- * 2. application/x-ndjson — one JSON object per line
107
- * 3. Any other — forwards raw text chunks
108
- *
109
- * JSON events (SSE and NDJSON) are parsed with deepFindText for universal
110
- * text extraction. Non-JSON content is forwarded as raw text.
111
- */
112
- export async function readStream(body, contentType, callbacks) {
113
- const reader = body.getReader();
114
- const decoder = new TextDecoder();
115
- const isSSE = contentType.includes('text/event-stream');
116
- const isNDJSON = contentType.includes('application/x-ndjson');
117
- let buffer = '';
118
- let doneSent = false;
119
- const emitDone = async () => {
120
- if (doneSent)
121
- return;
122
- doneSent = true;
123
- await callbacks.onDone();
124
- };
125
- const processJsonEvent = async (data) => {
126
- const hsid = extractHostSessionId(data);
127
- if (hsid)
128
- await callbacks.onHostSessionId?.(hsid);
129
- if (isStreamDone(data)) {
130
- await emitDone();
131
- return;
132
- }
133
- const text = deepFindText(data);
134
- if (text)
135
- await callbacks.onChunk(text);
136
- };
137
- try {
138
- for (;;) {
139
- const { done, value } = await reader.read();
140
- if (done)
141
- break;
142
- buffer += decoder.decode(value, { stream: true });
143
- if (isSSE) {
144
- const lines = buffer.split('\n');
145
- buffer = lines.pop() || '';
146
- for (const line of lines) {
147
- if (!line || line.startsWith(':'))
148
- continue;
149
- if (!line.startsWith('data: '))
150
- continue;
151
- const payload = line.slice(6).trim();
152
- if (!payload)
153
- continue;
154
- if (payload === '[DONE]') {
155
- await emitDone();
156
- continue;
157
- }
158
- try {
159
- await processJsonEvent(JSON.parse(payload));
160
- }
161
- catch {
162
- // Not valid JSON — forward as raw text chunk
163
- await callbacks.onChunk(payload);
164
- }
165
- }
166
- }
167
- else if (isNDJSON) {
168
- const lines = buffer.split('\n');
169
- buffer = lines.pop() || '';
170
- for (const line of lines) {
171
- const trimmed = line.trim();
172
- if (!trimmed)
173
- continue;
174
- try {
175
- await processJsonEvent(JSON.parse(trimmed));
176
- }
177
- catch {
178
- // Not valid JSON — forward as raw text chunk
179
- await callbacks.onChunk(trimmed);
180
- }
181
- }
182
- }
183
- else {
184
- const chunk = buffer;
185
- buffer = '';
186
- if (chunk)
187
- await callbacks.onChunk(chunk);
188
- }
189
- }
190
- await emitDone();
191
- }
192
- catch (err) {
193
- console.error('Stream reading error:', err);
194
- await emitDone().catch(() => { });
195
- }
196
- finally {
197
- reader.releaseLock();
198
- }
199
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"canvas-lifecycle.d.ts","sourceRoot":"","sources":["../../src/types/canvas-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,uBAAwB,SAAQ,UAAU;IACzD,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,oEAAoE;IACpE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,yBAA0B,SAAQ,UAAU;IAC3D,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,gEAAgE;IAChE,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAC;IACjE;;;;OAIG;IACH,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAqB,SAAQ,UAAU;IACtD,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,+DAA+D;IAC/D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAsB,SAAQ,UAAU;IACvD,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAC9B,uBAAuB,GACvB,yBAAyB,GACzB,oBAAoB,GACpB,qBAAqB,CAAC"}
@@ -1,41 +0,0 @@
1
- /**
2
- * Credential injection — cross-process wire protocol between the
3
- * open @ggui-ai/server auth relay (which writes placeholders) and
4
- * the closed cloud mcp-proxy service (which resolves them).
5
- *
6
- * Shared between:
7
- * - packages/server/src/mcp-auth-middleware.ts (writes placeholders)
8
- * - cloud/amplify/functions/rest-api/mcp-proxy/handler.ts (resolves placeholders)
9
- * - cloud/services/mcp-proxy/src/* (resolves placeholders)
10
- *
11
- * Hosted-overlay shapes for the `auth` block inside per-app
12
- * config files are a hosting concept and not a portable wire
13
- * protocol. What remains here is the runtime placeholder /
14
- * injection-mode protocol, which is legitimately cross-process.
15
- */
16
- /** How the proxy injects a credential into the outbound request. */
17
- export type CredentialInjection = 'bearer_header' | 'api_key_header' | 'query_param' | 'custom_header';
18
- /** Full injection config — resolved from app config or McpServiceConfig. */
19
- export interface CredentialInjectionConfig {
20
- mode: CredentialInjection;
21
- /** Header name for api_key_header / custom_header. Default: 'X-API-Key'. */
22
- headerName?: string;
23
- /** Query param name for query_param. Default: 'api_key'. */
24
- paramName?: string;
25
- }
26
- /**
27
- * Placeholder regex — matches `<ggui:credential:{serviceId}>`.
28
- * The placeholder is always the raw credential slot value.
29
- * The proxy applies injection formatting (Bearer prefix, header name, etc.).
30
- */
31
- export declare const CREDENTIAL_PLACEHOLDER_RE: RegExp;
32
- /**
33
- * Internal control header for placeholder pre-injection.
34
- * - Writer: auth relay middleware only
35
- * - Consumer: proxy only (reads, resolves, strips before forwarding)
36
- * - Never forwarded upstream
37
- */
38
- export declare const CREDENTIAL_HEADER = "x-ggui-credential";
39
- /** Build a placeholder string for a given serviceId. */
40
- export declare function credentialPlaceholder(serviceId: string): string;
41
- //# sourceMappingURL=credential.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"credential.d.ts","sourceRoot":"","sources":["../../src/types/credential.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,oEAAoE;AACpE,MAAM,MAAM,mBAAmB,GAC3B,eAAe,GACf,gBAAgB,GAChB,aAAa,GACb,eAAe,CAAC;AAEpB,4EAA4E;AAC5E,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,QAAyC,CAAC;AAEhF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AAErD,wDAAwD;AACxD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE/D"}
@@ -1,32 +0,0 @@
1
- /**
2
- * Credential injection — cross-process wire protocol between the
3
- * open @ggui-ai/server auth relay (which writes placeholders) and
4
- * the closed cloud mcp-proxy service (which resolves them).
5
- *
6
- * Shared between:
7
- * - packages/server/src/mcp-auth-middleware.ts (writes placeholders)
8
- * - cloud/amplify/functions/rest-api/mcp-proxy/handler.ts (resolves placeholders)
9
- * - cloud/services/mcp-proxy/src/* (resolves placeholders)
10
- *
11
- * Hosted-overlay shapes for the `auth` block inside per-app
12
- * config files are a hosting concept and not a portable wire
13
- * protocol. What remains here is the runtime placeholder /
14
- * injection-mode protocol, which is legitimately cross-process.
15
- */
16
- /**
17
- * Placeholder regex — matches `<ggui:credential:{serviceId}>`.
18
- * The placeholder is always the raw credential slot value.
19
- * The proxy applies injection formatting (Bearer prefix, header name, etc.).
20
- */
21
- export const CREDENTIAL_PLACEHOLDER_RE = /^<ggui:credential:([a-zA-Z0-9_-]+)>$/;
22
- /**
23
- * Internal control header for placeholder pre-injection.
24
- * - Writer: auth relay middleware only
25
- * - Consumer: proxy only (reads, resolves, strips before forwarding)
26
- * - Never forwarded upstream
27
- */
28
- export const CREDENTIAL_HEADER = 'x-ggui-credential';
29
- /** Build a placeholder string for a given serviceId. */
30
- export function credentialPlaceholder(serviceId) {
31
- return `<ggui:credential:${serviceId}>`;
32
- }