@ouispec/agent-worker 0.1.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 (191) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +175 -0
  3. package/dist/approvals/client.d.ts +29 -0
  4. package/dist/approvals/client.d.ts.map +1 -0
  5. package/dist/approvals/client.js +50 -0
  6. package/dist/approvals/client.js.map +1 -0
  7. package/dist/approvals/continuation.d.ts +28 -0
  8. package/dist/approvals/continuation.d.ts.map +1 -0
  9. package/dist/approvals/continuation.js +43 -0
  10. package/dist/approvals/continuation.js.map +1 -0
  11. package/dist/approvals/preview.d.ts +15 -0
  12. package/dist/approvals/preview.d.ts.map +1 -0
  13. package/dist/approvals/preview.js +33 -0
  14. package/dist/approvals/preview.js.map +1 -0
  15. package/dist/approvals/requirement.d.ts +15 -0
  16. package/dist/approvals/requirement.d.ts.map +1 -0
  17. package/dist/approvals/requirement.js +26 -0
  18. package/dist/approvals/requirement.js.map +1 -0
  19. package/dist/authz/tool-policy.d.ts +63 -0
  20. package/dist/authz/tool-policy.d.ts.map +1 -0
  21. package/dist/authz/tool-policy.js +23 -0
  22. package/dist/authz/tool-policy.js.map +1 -0
  23. package/dist/container/server.d.ts +24 -0
  24. package/dist/container/server.d.ts.map +1 -0
  25. package/dist/container/server.js +119 -0
  26. package/dist/container/server.js.map +1 -0
  27. package/dist/emit/http-adapter.d.ts +15 -0
  28. package/dist/emit/http-adapter.d.ts.map +1 -0
  29. package/dist/emit/http-adapter.js +35 -0
  30. package/dist/emit/http-adapter.js.map +1 -0
  31. package/dist/emit/types.d.ts +9 -0
  32. package/dist/emit/types.d.ts.map +1 -0
  33. package/dist/emit/types.js +7 -0
  34. package/dist/emit/types.js.map +1 -0
  35. package/dist/events/http-waiter.d.ts +19 -0
  36. package/dist/events/http-waiter.d.ts.map +1 -0
  37. package/dist/events/http-waiter.js +20 -0
  38. package/dist/events/http-waiter.js.map +1 -0
  39. package/dist/index.d.ts +60 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +45 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/lambda/handler.d.ts +38 -0
  44. package/dist/lambda/handler.d.ts.map +1 -0
  45. package/dist/lambda/handler.js +26 -0
  46. package/dist/lambda/handler.js.map +1 -0
  47. package/dist/model.d.ts +33 -0
  48. package/dist/model.d.ts.map +1 -0
  49. package/dist/model.js +15 -0
  50. package/dist/model.js.map +1 -0
  51. package/dist/openapi/document.d.ts +87 -0
  52. package/dist/openapi/document.d.ts.map +1 -0
  53. package/dist/openapi/document.js +117 -0
  54. package/dist/openapi/document.js.map +1 -0
  55. package/dist/openapi/executor.d.ts +51 -0
  56. package/dist/openapi/executor.d.ts.map +1 -0
  57. package/dist/openapi/executor.js +140 -0
  58. package/dist/openapi/executor.js.map +1 -0
  59. package/dist/openapi/index.d.ts +14 -0
  60. package/dist/openapi/index.d.ts.map +1 -0
  61. package/dist/openapi/index.js +9 -0
  62. package/dist/openapi/index.js.map +1 -0
  63. package/dist/openapi/loader.d.ts +81 -0
  64. package/dist/openapi/loader.d.ts.map +1 -0
  65. package/dist/openapi/loader.js +361 -0
  66. package/dist/openapi/loader.js.map +1 -0
  67. package/dist/openapi/x-agent.d.ts +34 -0
  68. package/dist/openapi/x-agent.d.ts.map +1 -0
  69. package/dist/openapi/x-agent.js +102 -0
  70. package/dist/openapi/x-agent.js.map +1 -0
  71. package/dist/orchestrator.d.ts +12 -0
  72. package/dist/orchestrator.d.ts.map +1 -0
  73. package/dist/orchestrator.js +1019 -0
  74. package/dist/orchestrator.js.map +1 -0
  75. package/dist/prompt/builder.d.ts +29 -0
  76. package/dist/prompt/builder.d.ts.map +1 -0
  77. package/dist/prompt/builder.js +129 -0
  78. package/dist/prompt/builder.js.map +1 -0
  79. package/dist/prompt/index.d.ts +15 -0
  80. package/dist/prompt/index.d.ts.map +1 -0
  81. package/dist/prompt/index.js +13 -0
  82. package/dist/prompt/index.js.map +1 -0
  83. package/dist/prompt/rules/base.d.ts +6 -0
  84. package/dist/prompt/rules/base.d.ts.map +1 -0
  85. package/dist/prompt/rules/base.js +38 -0
  86. package/dist/prompt/rules/base.js.map +1 -0
  87. package/dist/prompt/rules/communication.d.ts +7 -0
  88. package/dist/prompt/rules/communication.d.ts.map +1 -0
  89. package/dist/prompt/rules/communication.js +53 -0
  90. package/dist/prompt/rules/communication.js.map +1 -0
  91. package/dist/prompt/rules/tool-strategy.d.ts +6 -0
  92. package/dist/prompt/rules/tool-strategy.d.ts.map +1 -0
  93. package/dist/prompt/rules/tool-strategy.js +42 -0
  94. package/dist/prompt/rules/tool-strategy.js.map +1 -0
  95. package/dist/prompt/rules/ui-control.d.ts +10 -0
  96. package/dist/prompt/rules/ui-control.d.ts.map +1 -0
  97. package/dist/prompt/rules/ui-control.js +44 -0
  98. package/dist/prompt/rules/ui-control.js.map +1 -0
  99. package/dist/prompt/types.d.ts +85 -0
  100. package/dist/prompt/types.d.ts.map +1 -0
  101. package/dist/prompt/types.js +10 -0
  102. package/dist/prompt/types.js.map +1 -0
  103. package/dist/realtime/long-poll.d.ts +21 -0
  104. package/dist/realtime/long-poll.d.ts.map +1 -0
  105. package/dist/realtime/long-poll.js +36 -0
  106. package/dist/realtime/long-poll.js.map +1 -0
  107. package/dist/runtime/config.d.ts +4 -0
  108. package/dist/runtime/config.d.ts.map +1 -0
  109. package/dist/runtime/config.js +29 -0
  110. package/dist/runtime/config.js.map +1 -0
  111. package/dist/runtime/turn-runner.d.ts +32 -0
  112. package/dist/runtime/turn-runner.d.ts.map +1 -0
  113. package/dist/runtime/turn-runner.js +216 -0
  114. package/dist/runtime/turn-runner.js.map +1 -0
  115. package/dist/runtime/types.d.ts +244 -0
  116. package/dist/runtime/types.d.ts.map +1 -0
  117. package/dist/runtime/types.js +2 -0
  118. package/dist/runtime/types.js.map +1 -0
  119. package/dist/testing/desk-events.d.ts +12 -0
  120. package/dist/testing/desk-events.d.ts.map +1 -0
  121. package/dist/testing/desk-events.js +62 -0
  122. package/dist/testing/desk-events.js.map +1 -0
  123. package/dist/testing/index.d.ts +8 -0
  124. package/dist/testing/index.d.ts.map +1 -0
  125. package/dist/testing/index.js +7 -0
  126. package/dist/testing/index.js.map +1 -0
  127. package/dist/testing/openapi-fixture.d.ts +47 -0
  128. package/dist/testing/openapi-fixture.d.ts.map +1 -0
  129. package/dist/testing/openapi-fixture.js +370 -0
  130. package/dist/testing/openapi-fixture.js.map +1 -0
  131. package/dist/tools/async-binding.d.ts +71 -0
  132. package/dist/tools/async-binding.d.ts.map +1 -0
  133. package/dist/tools/async-binding.js +104 -0
  134. package/dist/tools/async-binding.js.map +1 -0
  135. package/dist/tools/builtin-tools.d.ts +20 -0
  136. package/dist/tools/builtin-tools.d.ts.map +1 -0
  137. package/dist/tools/builtin-tools.js +108 -0
  138. package/dist/tools/builtin-tools.js.map +1 -0
  139. package/dist/tools/entity-tools.d.ts +6 -0
  140. package/dist/tools/entity-tools.d.ts.map +1 -0
  141. package/dist/tools/entity-tools.js +227 -0
  142. package/dist/tools/entity-tools.js.map +1 -0
  143. package/dist/tools/input-validation.d.ts +16 -0
  144. package/dist/tools/input-validation.d.ts.map +1 -0
  145. package/dist/tools/input-validation.js +75 -0
  146. package/dist/tools/input-validation.js.map +1 -0
  147. package/dist/tools/load-all-tools.d.ts +12 -0
  148. package/dist/tools/load-all-tools.d.ts.map +1 -0
  149. package/dist/tools/load-all-tools.js +42 -0
  150. package/dist/tools/load-all-tools.js.map +1 -0
  151. package/dist/tools/schema-loader.d.ts +24 -0
  152. package/dist/tools/schema-loader.d.ts.map +1 -0
  153. package/dist/tools/schema-loader.js +267 -0
  154. package/dist/tools/schema-loader.js.map +1 -0
  155. package/dist/tools/types.d.ts +85 -0
  156. package/dist/tools/types.d.ts.map +1 -0
  157. package/dist/tools/types.js +22 -0
  158. package/dist/tools/types.js.map +1 -0
  159. package/dist/turn-policy.d.ts +68 -0
  160. package/dist/turn-policy.d.ts.map +1 -0
  161. package/dist/turn-policy.js +21 -0
  162. package/dist/turn-policy.js.map +1 -0
  163. package/dist/types.d.ts +151 -0
  164. package/dist/types.d.ts.map +1 -0
  165. package/dist/types.js +2 -0
  166. package/dist/types.js.map +1 -0
  167. package/dist/ui/channel.d.ts +64 -0
  168. package/dist/ui/channel.d.ts.map +1 -0
  169. package/dist/ui/channel.js +81 -0
  170. package/dist/ui/channel.js.map +1 -0
  171. package/dist/ui/knowledge.d.ts +30 -0
  172. package/dist/ui/knowledge.d.ts.map +1 -0
  173. package/dist/ui/knowledge.js +66 -0
  174. package/dist/ui/knowledge.js.map +1 -0
  175. package/dist/ui/observations.d.ts +41 -0
  176. package/dist/ui/observations.d.ts.map +1 -0
  177. package/dist/ui/observations.js +236 -0
  178. package/dist/ui/observations.js.map +1 -0
  179. package/dist/ui/snapshot.d.ts +33 -0
  180. package/dist/ui/snapshot.d.ts.map +1 -0
  181. package/dist/ui/snapshot.js +75 -0
  182. package/dist/ui/snapshot.js.map +1 -0
  183. package/dist/ui/ui-sequence.d.ts +75 -0
  184. package/dist/ui/ui-sequence.d.ts.map +1 -0
  185. package/dist/ui/ui-sequence.js +73 -0
  186. package/dist/ui/ui-sequence.js.map +1 -0
  187. package/dist/ui/ui-tools.d.ts +59 -0
  188. package/dist/ui/ui-tools.d.ts.map +1 -0
  189. package/dist/ui/ui-tools.js +244 -0
  190. package/dist/ui/ui-tools.js.map +1 -0
  191. package/package.json +78 -0
@@ -0,0 +1,21 @@
1
+ /**
2
+ * TurnPolicy — controls per-step tool selection and constraints.
3
+ *
4
+ * Integrators provide their own policy to encode product-specific orchestration
5
+ * behavior (e.g. forced tool sequences for onboarding, navigation-first flows).
6
+ * The SDK provides a safe, product-neutral default.
7
+ *
8
+ * The policy is consulted at two points:
9
+ * 1. classifyTurn — called once at turn start to classify the user's intent
10
+ * 2. prepareStep — called before each LLM step to control tool selection
11
+ */
12
+ /**
13
+ * Default turn policy — product-neutral, safe defaults.
14
+ * No forced tool sequences, no product-specific constraints.
15
+ * The orchestrator's existing step count and token limits provide the safety net.
16
+ */
17
+ export const defaultTurnPolicy = {
18
+ classifyTurn: () => 'normal',
19
+ prepareStep: async () => ({}),
20
+ };
21
+ //# sourceMappingURL=turn-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turn-policy.js","sourceRoot":"","sources":["../src/turn-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA8CH;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAe;IAC3C,YAAY,EAAE,GAAG,EAAE,CAAC,QAAQ;IAC5B,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;CAC9B,CAAC"}
@@ -0,0 +1,151 @@
1
+ import type { LanguageModel, ProviderOptions } from './model.js';
2
+ import type { RealtimeEmitAdapter } from './emit/types.js';
3
+ import type { ToolRegistry } from './tools/types.js';
4
+ import type { TurnPolicy } from './turn-policy.js';
5
+ import type { ToolPolicy } from './authz/tool-policy.js';
6
+ import type { UIActionChannel } from './ui/channel.js';
7
+ import type { ApprovalStoreClient } from './approvals/client.js';
8
+ import type { ApprovalContinuation } from '@ouispec/agent-core';
9
+ /**
10
+ * Configuration for the agent worker.
11
+ * Platforms provide this to run the orchestration loop.
12
+ */
13
+ export interface AgentWorkerConfig {
14
+ tools: ToolRegistry;
15
+ emit: RealtimeEmitAdapter;
16
+ /**
17
+ * The host's AgentApiSurface binding, threaded into ToolExecutionContext
18
+ * so schema-generated tools can call executeIntent. Optional.
19
+ */
20
+ apiSurface?: import('@ouispec/agent-core').AgentApiSurface;
21
+ systemPrompt: string | ((context: SystemPromptContext) => string);
22
+ /** The model, from any `ai` library provider (ADR-0227 §2.2). Required. */
23
+ model: LanguageModel;
24
+ /**
25
+ * Provider options that mark a prompt-cache breakpoint, placed after the
26
+ * system prompt (which covers the tools) and at the end of the history.
27
+ * See PROMPT_CACHE_BREAKPOINTS. Omit for a provider that caches on its own.
28
+ */
29
+ promptCacheBreakpoint?: ProviderOptions;
30
+ maxToolRounds?: number;
31
+ maxTokens?: number;
32
+ temperature?: number;
33
+ toolTimeoutMs?: number;
34
+ turnDeadlineMs?: number;
35
+ retries?: number;
36
+ /** Optional turn policy for product-specific step control. */
37
+ turnPolicy?: TurnPolicy;
38
+ /**
39
+ * Per-tool authorization policy. Evaluated before every tool execution.
40
+ * If omitted, the default policy allows all tools.
41
+ * Policy errors are fail-closed (treated as deny).
42
+ */
43
+ toolPolicy?: ToolPolicy;
44
+ /**
45
+ * The approval store (ADR-0228), in the realtime server. A call that needs
46
+ * the user's approval is stored there and the turn stops; without a store,
47
+ * such a call is refused and never runs.
48
+ */
49
+ approvals?: ApprovalStoreClient;
50
+ /**
51
+ * How UI actions reach the client that sent the turn and how its answers
52
+ * come back (ADR-0209). Required when a turn's context carries a client
53
+ * snapshot (`context.oui`).
54
+ */
55
+ ui?: {
56
+ channel: UIActionChannel;
57
+ /** How long a UI tool waits for the client's answer. Default 20 s. */
58
+ resultTimeoutMs?: number;
59
+ /** Largest page-state payload given to the model, in characters. Default 6000. */
60
+ maxObservationChars?: number;
61
+ };
62
+ }
63
+ export interface SystemPromptContext {
64
+ userId: string;
65
+ accountId: string;
66
+ context?: Record<string, unknown> | null;
67
+ }
68
+ /**
69
+ * Input for a single agent turn.
70
+ */
71
+ export interface AgentTurnInput {
72
+ turnId: string;
73
+ conversationId: string;
74
+ userId: string;
75
+ accountId: string;
76
+ socketRoom: string;
77
+ content: string;
78
+ context?: Record<string, unknown> | null;
79
+ history?: TurnHistoryMessage[];
80
+ userToken?: string;
81
+ /**
82
+ * Set on the turn that follows the user's decision on an approval card: the
83
+ * token to redeem, or that they declined (ADR-0228 §2.2.5). Never in the
84
+ * message text.
85
+ */
86
+ approval?: ApprovalContinuation;
87
+ }
88
+ /**
89
+ * Rich history message — supports full conversation state including tool calls and results.
90
+ * This is the format integrators prepare from their conversation store.
91
+ */
92
+ export type TurnHistoryMessage = {
93
+ role: 'user';
94
+ content: string;
95
+ } | {
96
+ role: 'assistant';
97
+ content: string | null;
98
+ tool_calls?: ToolCallRef[];
99
+ } | {
100
+ role: 'tool';
101
+ content: string;
102
+ tool_call_id: string;
103
+ name?: string;
104
+ };
105
+ export interface ToolCallRef {
106
+ id: string;
107
+ type?: string;
108
+ function: {
109
+ name: string;
110
+ arguments: string;
111
+ };
112
+ }
113
+ /**
114
+ * Result from a completed agent turn.
115
+ */
116
+ export interface AgentTurnResult {
117
+ rounds: number;
118
+ usage: {
119
+ /** Input tokens summed over every round of the turn — what the turn cost. */
120
+ promptTokens: number;
121
+ completionTokens: number;
122
+ totalTokens: number;
123
+ /**
124
+ * Input tokens on the LARGEST single round — what the context window sees.
125
+ * Compare a context ceiling against this, never against `promptTokens`:
126
+ * the sum grows with round count and reports a context problem that is not
127
+ * there while staying silent about one that is.
128
+ */
129
+ peakPromptTokens: number;
130
+ /** Prefix tokens served from cache. Zero across a multi-round turn means the cache is being missed. */
131
+ cacheReadTokens: number;
132
+ /** Prefix tokens written to cache — expected on the first round of a turn. */
133
+ cacheWriteTokens: number;
134
+ };
135
+ newMessages: TurnMessage[];
136
+ maxRoundsReached: boolean;
137
+ /** Why the turn ended: which bound or condition terminated the loop */
138
+ stopReason: 'present_options' | 'awaiting_approval' | 'step_count' | 'token_budget' | 'deadline' | 'complete' | 'error';
139
+ }
140
+ export interface TurnMessage {
141
+ role: 'assistant' | 'tool';
142
+ content: string | null;
143
+ toolCalls?: Array<{
144
+ id: string;
145
+ name: string;
146
+ arguments: Record<string, unknown>;
147
+ }>;
148
+ toolCallId?: string;
149
+ name?: string;
150
+ }
151
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,KAAK,EA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EAAE,MAAM,CAAC;IACf,KAAK,EAAE;QACL,6EAA6E;QAC7E,YAAY,EAAE,MAAM,CAAC;QACrB,gBAAgB,EAAE,MAAM,CAAC;QACzB,WAAW,EAAE,MAAM,CAAC;QACpB;;;;;WAKG;QACH,gBAAgB,EAAE,MAAM,CAAC;QACzB,uGAAuG;QACvG,eAAe,EAAE,MAAM,CAAC;QACxB,8EAA8E;QAC9E,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,WAAW,EAAE,WAAW,EAAE,CAAC;IAC3B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,uEAAuE;IACvE,UAAU,EAAE,iBAAiB,GAAG,mBAAmB,GAAG,YAAY,GAAG,cAAc,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC;CACzH;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,WAAW,GAAG,MAAM,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,CAAC,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;IACpF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The UI action channel: how the worker sends a UI action to the client that
3
+ * sent the turn, and how it gets the client's answer (ADR-0209 D2).
4
+ *
5
+ * The worker is not on the client's socket. It reaches the client through the
6
+ * realtime service: the request is emitted to the turn's room, the client
7
+ * answers on OUI's result event, and the realtime service holds that answer
8
+ * until the worker collects it.
9
+ */
10
+ import type { OUIActionRequest, OUIActionResult } from 'oui-spec/spec';
11
+ /**
12
+ * Who received a request: how many of the room's tabs acknowledged it, and how
13
+ * many accepted it (oui-spec §7.3.7). Null from a realtime service that does
14
+ * not report receipts.
15
+ */
16
+ export interface UIDispatchReceipt {
17
+ acknowledged: number;
18
+ accepted: number;
19
+ }
20
+ export interface UIActionChannel {
21
+ /**
22
+ * Deliver a request to the turn's room, and say who received it when the
23
+ * realtime service reports receipts. Rejects when it could not be delivered.
24
+ */
25
+ dispatch(room: string, request: OUIActionRequest): Promise<UIDispatchReceipt | null | void>;
26
+ /**
27
+ * Resolve with the client's first answer to `requestId`, or null if none
28
+ * arrives by the deadline. Only an answer from a client authenticated as
29
+ * `userId` counts. With `final`, the final answer instead: for an async
30
+ * action, the one sent once its work is done or has failed, never its
31
+ * acknowledgment.
32
+ */
33
+ awaitResult(requestId: string, options: {
34
+ userId: string;
35
+ timeoutMs: number;
36
+ signal?: AbortSignal;
37
+ final?: boolean;
38
+ }): Promise<OUIActionResult | null>;
39
+ }
40
+ export interface HttpUIActionChannelConfig {
41
+ /** The realtime service's base URL. */
42
+ url: string;
43
+ /** Its internal API key (the same key the emit adapter uses). */
44
+ apiKey: string;
45
+ /** Longest single wait the realtime service is asked to hold open. Default 20 s. */
46
+ maxPollMs?: number;
47
+ /** Timeout for delivering a request. Default 5 s. */
48
+ dispatchTimeoutMs?: number;
49
+ /**
50
+ * How long the realtime service waits for the tabs' receipts of a request
51
+ * before answering the delivery (oui-spec §7.3.7). Default 1.5 s; 0 asks for
52
+ * none.
53
+ */
54
+ receiptTimeoutMs?: number;
55
+ }
56
+ /**
57
+ * The channel over the realtime service's HTTP API:
58
+ * - `POST {url}/api/emit` delivers the request to the turn's room;
59
+ * - `GET {url}/internal/oui/action-results/{requestId}?userId=&waitMs=` waits
60
+ * for the answer (200 with the result, 204 when none arrived in `waitMs`);
61
+ * with `&final=1`, for the final answer of an async action.
62
+ */
63
+ export declare function createHttpUIActionChannel(config: HttpUIActionChannelConfig): UIActionChannel;
64
+ //# sourceMappingURL=channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/ui/channel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAKvE;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;IAE5F;;;;;;OAMG;IACH,WAAW,CACT,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GACpF,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,yBAAyB;IACxC,uCAAuC;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAyBD;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,yBAAyB,GAAG,eAAe,CAyC5F"}
@@ -0,0 +1,81 @@
1
+ import { createWebSocketTransport } from 'oui-spec/transport';
2
+ import { requireRealtime } from '../emit/http-adapter.js';
3
+ import { longPoll } from '../realtime/long-poll.js';
4
+ /**
5
+ * The OUI wire name for a dispatch, taken from OUI's own transport rather than
6
+ * written here: OUI owns its event names, and a copy of one here is how the
7
+ * two ends drift apart.
8
+ */
9
+ function ouiDispatchEvent(request) {
10
+ let captured = null;
11
+ const capture = {
12
+ connected: true,
13
+ emit(event, data) {
14
+ captured = { event, data };
15
+ },
16
+ on() { },
17
+ off() { },
18
+ once() { },
19
+ };
20
+ const transport = createWebSocketTransport(capture);
21
+ transport.dispatch(request);
22
+ transport.dispose();
23
+ if (!captured)
24
+ throw new Error('[agent-sdk] OUI transport emitted nothing for a dispatch');
25
+ return captured;
26
+ }
27
+ /**
28
+ * The channel over the realtime service's HTTP API:
29
+ * - `POST {url}/api/emit` delivers the request to the turn's room;
30
+ * - `GET {url}/internal/oui/action-results/{requestId}?userId=&waitMs=` waits
31
+ * for the answer (200 with the result, 204 when none arrived in `waitMs`);
32
+ * with `&final=1`, for the final answer of an async action.
33
+ */
34
+ export function createHttpUIActionChannel(config) {
35
+ const { url, apiKey } = config;
36
+ requireRealtime(url, apiKey);
37
+ const maxPollMs = config.maxPollMs ?? 20_000;
38
+ const dispatchTimeoutMs = config.dispatchTimeoutMs ?? 5_000;
39
+ const receiptTimeoutMs = config.receiptTimeoutMs ?? 1_500;
40
+ return {
41
+ async dispatch(room, request) {
42
+ const { event, data } = ouiDispatchEvent(request);
43
+ const res = await fetch(`${url}/api/emit`, {
44
+ method: 'POST',
45
+ headers: { 'Content-Type': 'application/json', 'X-Api-Key': apiKey },
46
+ body: JSON.stringify({
47
+ event,
48
+ data,
49
+ rooms: [room],
50
+ ...(receiptTimeoutMs > 0 ? { ackTimeoutMs: receiptTimeoutMs } : {}),
51
+ }),
52
+ signal: AbortSignal.timeout(dispatchTimeoutMs + receiptTimeoutMs),
53
+ });
54
+ if (!res.ok) {
55
+ throw new Error(`[agent-sdk] Delivering UI action ${request.actionId} failed: HTTP ${res.status}`);
56
+ }
57
+ return receiptsOf(await res.json().catch(() => null));
58
+ },
59
+ awaitResult(requestId, { userId, timeoutMs, signal, final }) {
60
+ return longPoll({
61
+ url: (waitMs) => {
62
+ const query = new URLSearchParams({ userId, waitMs: String(waitMs), ...(final ? { final: '1' } : {}) });
63
+ return `${url}/internal/oui/action-results/${encodeURIComponent(requestId)}?${query}`;
64
+ },
65
+ apiKey,
66
+ timeoutMs,
67
+ maxPollMs,
68
+ ...(signal ? { signal } : {}),
69
+ describe: `the result of UI action ${requestId}`,
70
+ });
71
+ },
72
+ };
73
+ }
74
+ /** The receipts in an emit's response, or null when the realtime service reported none. */
75
+ function receiptsOf(body) {
76
+ const receipts = body?.receipts;
77
+ if (!receipts || typeof receipts.acknowledged !== 'number' || typeof receipts.accepted !== 'number')
78
+ return null;
79
+ return { acknowledged: receipts.acknowledged, accepted: receipts.accepted };
80
+ }
81
+ //# sourceMappingURL=channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel.js","sourceRoot":"","sources":["../../src/ui/channel.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,wBAAwB,EAAmB,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAiDpD;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,OAAyB;IACjD,IAAI,QAAQ,GAA4C,IAAI,CAAC;IAC7D,MAAM,OAAO,GAAe;QAC1B,SAAS,EAAE,IAAI;QACf,IAAI,CAAC,KAAK,EAAE,IAAI;YACd,QAAQ,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;QACD,EAAE,KAAI,CAAC;QACP,GAAG,KAAI,CAAC;QACR,IAAI,KAAI,CAAC;KACV,CAAC;IACF,MAAM,SAAS,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACpD,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC5B,SAAS,CAAC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0,0 +1,30 @@
1
+ /**
2
+ * The client's knowledge, carried on the turn.
3
+ *
4
+ * A UI client's generator emits knowledge from the same code declarations as
5
+ * its surfaces (ADR-0220, ADR-0226): the app's map, each page in full, how its
6
+ * parts relate, and the recipes its controls imply. The tab resolves it for the
7
+ * page the user is on (oui-bindings' `resolveKnowledge`) and sends it with the
8
+ * turn under `uiKnowledge`, beside its surface snapshot under `oui`.
9
+ *
10
+ * The worker renders it into the system prompt after the host's own prompt, for
11
+ * every host: a persona or a `systemPrompt` callback never sees it as context
12
+ * and never has to render it.
13
+ */
14
+ import type { ResolvedKnowledge } from '@ouispec/bindings';
15
+ /** The context key a UI client uses for its knowledge. */
16
+ export declare const CLIENT_KNOWLEDGE_KEY = "uiKnowledge";
17
+ /** What a UI client sends: the knowledge for the page the user is on. */
18
+ export type ClientKnowledge = ResolvedKnowledge;
19
+ /**
20
+ * Read and validate the knowledge from a turn's context. Returns null when the
21
+ * turn carries none (a client with no UI), and throws when it carries knowledge
22
+ * that is malformed: a broken payload is a client bug that must not quietly
23
+ * become "this client knows nothing".
24
+ */
25
+ export declare function readClientKnowledge(context: Record<string, unknown> | null | undefined): ClientKnowledge | null;
26
+ /** The knowledge as a prompt section: every entry, then every workflow with its numbered steps. */
27
+ export declare function renderClientKnowledge(knowledge: ClientKnowledge): string;
28
+ /** The host's system prompt, followed by the knowledge the turn's client sent, if any. */
29
+ export declare function withClientKnowledge(systemPrompt: string, context: Record<string, unknown> | null | undefined): string;
30
+ //# sourceMappingURL=knowledge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knowledge.d.ts","sourceRoot":"","sources":["../../src/ui/knowledge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,0DAA0D;AAC1D,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAElD,yEAAyE;AACzE,MAAM,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,eAAe,GAAG,IAAI,CAe/G;AAED,mGAAmG;AACnG,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,eAAe,GAAG,MAAM,CAgBxE;AAED,0FAA0F;AAC1F,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAIrH"}
@@ -0,0 +1,66 @@
1
+ /** The context key a UI client uses for its knowledge. */
2
+ export const CLIENT_KNOWLEDGE_KEY = 'uiKnowledge';
3
+ /**
4
+ * Read and validate the knowledge from a turn's context. Returns null when the
5
+ * turn carries none (a client with no UI), and throws when it carries knowledge
6
+ * that is malformed: a broken payload is a client bug that must not quietly
7
+ * become "this client knows nothing".
8
+ */
9
+ export function readClientKnowledge(context) {
10
+ const raw = context?.[CLIENT_KNOWLEDGE_KEY];
11
+ if (raw === undefined || raw === null)
12
+ return null;
13
+ const where = `context.${CLIENT_KNOWLEDGE_KEY}`;
14
+ if (typeof raw !== 'object')
15
+ throw new Error(`[agent-sdk] ${where} must be an object`);
16
+ const { entries, workflows } = raw;
17
+ if (!Array.isArray(entries))
18
+ throw new Error(`[agent-sdk] ${where}.entries must be an array`);
19
+ if (!Array.isArray(workflows))
20
+ throw new Error(`[agent-sdk] ${where}.workflows must be an array`);
21
+ entries.forEach((e, i) => {
22
+ if (!isEntry(e))
23
+ throw new Error(`[agent-sdk] ${where}.entries[${i}] is not a knowledge entry (title, content)`);
24
+ });
25
+ workflows.forEach((w, i) => {
26
+ if (!isWorkflow(w))
27
+ throw new Error(`[agent-sdk] ${where}.workflows[${i}] is not a workflow (name, trigger, steps[])`);
28
+ });
29
+ return { entries, workflows };
30
+ }
31
+ /** The knowledge as a prompt section: every entry, then every workflow with its numbered steps. */
32
+ export function renderClientKnowledge(knowledge) {
33
+ const sections = [];
34
+ if (knowledge.entries.length > 0) {
35
+ sections.push('## Platform Knowledge (Context-Aware)\n\n' + knowledge.entries.map((e) => `### ${e.title}\n${e.content}`).join('\n\n'));
36
+ }
37
+ if (knowledge.workflows.length > 0) {
38
+ sections.push('## Active Workflows\n\n' +
39
+ knowledge.workflows
40
+ .map((w) => `### ${w.name}\nTrigger: ${w.trigger}\nSteps:\n${w.steps.map((s, i) => `${i + 1}. ${s}`).join('\n')}`)
41
+ .join('\n\n'));
42
+ }
43
+ return sections.join('\n\n');
44
+ }
45
+ /** The host's system prompt, followed by the knowledge the turn's client sent, if any. */
46
+ export function withClientKnowledge(systemPrompt, context) {
47
+ const knowledge = readClientKnowledge(context);
48
+ const rendered = knowledge ? renderClientKnowledge(knowledge) : '';
49
+ return rendered ? `${systemPrompt}\n\n${rendered}` : systemPrompt;
50
+ }
51
+ function isEntry(value) {
52
+ if (!value || typeof value !== 'object')
53
+ return false;
54
+ const e = value;
55
+ return typeof e.title === 'string' && typeof e.content === 'string';
56
+ }
57
+ function isWorkflow(value) {
58
+ if (!value || typeof value !== 'object')
59
+ return false;
60
+ const w = value;
61
+ return (typeof w.name === 'string' &&
62
+ typeof w.trigger === 'string' &&
63
+ Array.isArray(w.steps) &&
64
+ w.steps.every((s) => typeof s === 'string'));
65
+ }
66
+ //# sourceMappingURL=knowledge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knowledge.js","sourceRoot":"","sources":["../../src/ui/knowledge.ts"],"names":[],"mappings":"AAeA,0DAA0D;AAC1D,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAKlD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAmD;IACrF,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC,oBAAoB,CAAC,CAAC;IAC5C,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI;Q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AU,CAAC,KAAc;IAChC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,CAAC,GAAG,KAAgC,CAAC;IAC3C,OAAO,CACL,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ;QAC1B,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ;QAC7B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;QACtB,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAC5C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Page state within the model's budget, problems first (ADR-0167).
3
+ *
4
+ * A surface may publish a `problems` observation: what its page cannot draw,
5
+ * load or read — a face it does not have and the text it therefore hides, an
6
+ * asset that failed, what an import could not reproduce. Those are exactly
7
+ * what the model must not miss before it tells the user a result, so when the
8
+ * page state is over budget they are kept whole and only the rest is cut. So
9
+ * are the statuses of the jobs the page follows: whether what an action
10
+ * started has finished is how the model knows it may say so.
11
+ */
12
+ import type { OUIObservationSnapshot } from 'oui-spec/spec';
13
+ /** The observation id a surface reports its page's problems under. */
14
+ export declare const PROBLEMS_OBSERVATION_ID = "problems";
15
+ /** Every surface's non-empty `problems`, by surface id; null when none reports any. */
16
+ export declare function surfaceProblems(observations: OUIObservationSnapshot): Record<string, unknown> | null;
17
+ /**
18
+ * Every job an action started that the page is following: each surface's
19
+ * `<surface>:<action>:status` observations (started, running, complete with
20
+ * what it made, failed with why), by surface id; null when there are none.
21
+ * The model is told an action like Generate is done only through these, so
22
+ * they must reach it whatever else the page reports.
23
+ */
24
+ export declare function jobStatuses(observations: OUIObservationSnapshot): Record<string, Record<string, unknown>> | null;
25
+ /** Rows past this in any list are summed up as "… and N more" at the first step of fitting an over-budget page state. */
26
+ export declare const MAX_LIST_ROWS = 20;
27
+ /**
28
+ * A list this short is never shortened: it is a field's choices (the engines a
29
+ * voice can speak with, a document's types), not a collection to browse.
30
+ */
31
+ export declare const WHOLE_LIST_ROWS = 5;
32
+ /**
33
+ * The observations as the model receives them: whole when they fit. Over
34
+ * budget, every surface's problems and job statuses are kept whole; the rest is
35
+ * fitted (see fitted): long lists shortened first, the page it acted on first
36
+ * and kept whole, and only if that still does not fit is the rest cut, saying so.
37
+ */
38
+ export declare function boundObservations(observations: OUIObservationSnapshot, maxChars: number, actingSurfaceId?: string): unknown;
39
+ /** The same, as the text of a `<page_state>` block. */
40
+ export declare function observationsText(observations: OUIObservationSnapshot, maxChars: number): string;
41
+ //# sourceMappingURL=observations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observations.d.ts","sourceRoot":"","sources":["../../src/ui/observations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAE5D,sEAAsE;AACtE,eAAO,MAAM,uBAAuB,aAAa,CAAC;AAElD,uFAAuF;AACvF,wBAAgB,eAAe,CAAC,YAAY,EAAE,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CASpG;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,IAAI,CAShH;AAgBD,yHAAyH;AACzH,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC;;;GAGG;AACH,eAAO,MAAM,eAAe,IAAI,CAAC;AAgKjC;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,sBAAsB,EACpC,QAAQ,EAAE,MAAM,EAChB,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAcT;AAED,uDAAuD;AACvD,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAc/F"}