@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,361 @@
1
+ /**
2
+ * loadOpenApiTools — a product's OpenAPI 3 document becomes its agent tools
3
+ * (ADR-0181 §2). No second manifest format: the document is read directly.
4
+ *
5
+ * - An operation is a tool only when its `x-agent` says `expose: true`.
6
+ * - Its name is its `operationId`; its description its `summary` and `description`;
7
+ * its input its parameters and JSON request body, validated by the worker before
8
+ * every call.
9
+ * - Its effect and `destructive` come from `x-agent`, and are on the tool for
10
+ * approvals to key on (ADR-0228).
11
+ * - Its required permissions are its standard `security` requirement.
12
+ * - A call runs as the caller the required `actAs` seam names, and the API decides
13
+ * what that caller may do.
14
+ * - The product's own assistant (`audience: 'pa'`) gets only the operations flagged
15
+ * `pa: true`, and the flag is refused on anything but a read (ADR-0227 §2.1).
16
+ * - An operation that starts a job names its declared completion event in
17
+ * `x-async-binding` (W9). It is checked against the product's declarations at
18
+ * load, and with a waiter the tool waits for the job to settle.
19
+ *
20
+ * Anything that cannot become a safe, callable tool is refused at load, naming the
21
+ * operation.
22
+ */
23
+ import { effectAccess, effectKind } from '@ouispec/bindings';
24
+ import { asyncToolResult, awaitAsyncTool, bindAsyncTool, parseWaitTimeout } from '../tools/async-binding.js';
25
+ import { HTTP_METHODS, OpenApiToolError, createResolver, toInputSchema, } from './document.js';
26
+ import { executeOperation } from './executor.js';
27
+ import { readAgentExposure } from './x-agent.js';
28
+ /** Model providers accept tool names of this shape. */
29
+ const TOOL_NAME = /^[a-zA-Z0-9_-]{1,64}$/;
30
+ const QUERY_STYLES = new Set(['form', 'spaceDelimited', 'pipeDelimited', 'deepObject']);
31
+ function describeOperation(method, path, operationId) {
32
+ return `${method.toUpperCase()} ${path}${operationId ? ` (${operationId})` : ''}`;
33
+ }
34
+ function jsonMediaType(content) {
35
+ return Object.keys(content ?? {}).find((type) => /^application\/(?:[\w.+-]+\+)?json(?:\s*;.*)?$/i.test(type));
36
+ }
37
+ /** The operation's parameters: the path item's, overridden by the operation's own of the same name and place. */
38
+ function mergedParameters(pathParams, opParams, resolver, where) {
39
+ const byKey = new Map();
40
+ for (const raw of [...(pathParams ?? []), ...(opParams ?? [])]) {
41
+ const param = resolver.deref(raw, where);
42
+ if (!param || typeof param.name !== 'string' || !['path', 'query', 'header', 'cookie'].includes(param.in)) {
43
+ throw new OpenApiToolError(`${where}: a parameter has no name or no valid "in"`);
44
+ }
45
+ byKey.set(`${param.in}:${param.name}`, param);
46
+ }
47
+ return [...byKey.values()];
48
+ }
49
+ function effectSentences(effect, destructive, consequence) {
50
+ const sentences = [];
51
+ switch (effectKind(effect)) {
52
+ case 'job':
53
+ sentences.push('It starts a job: the call returns once the job has started, and the job is done only when its status says complete.');
54
+ break;
55
+ case 'transaction':
56
+ sentences.push('It is irreversible: it runs only on the person’s approval of this exact call.');
57
+ break;
58
+ default:
59
+ break;
60
+ }
61
+ if (destructive)
62
+ sentences.push('It removes or replaces something the person made.');
63
+ if (consequence)
64
+ sentences.push(consequence);
65
+ return sentences;
66
+ }
67
+ function buildInput(path, parameters, requestBody, resolver, where) {
68
+ const properties = {};
69
+ const required = [];
70
+ const placements = new Map();
71
+ const requiredHeaders = [];
72
+ const templateNames = [...path.matchAll(/\{([^}]+)\}/g)].map((m) => m[1]);
73
+ for (const name of templateNames) {
74
+ if (!parameters.some((p) => p.in === 'path' && p.name === name)) {
75
+ throw new OpenApiToolError(`${where}: the path names {${name}}, which no path parameter declares`);
76
+ }
77
+ }
78
+ for (const param of parameters) {
79
+ if (param.in === 'header' || param.in === 'cookie') {
80
+ // The caller's identity and context headers come only from actAs, never from the model.
81
+ if (param.required) {
82
+ if (param.in === 'cookie')
83
+ throw new OpenApiToolError(`${where}: it requires the cookie ${param.name}, which a tool cannot send`);
84
+ requiredHeaders.push(param.name);
85
+ }
86
+ continue;
87
+ }
88
+ if (param.in === 'path' && !templateNames.includes(param.name)) {
89
+ throw new OpenApiToolError(`${where}: path parameter ${param.name} is not in the path`);
90
+ }
91
+ if (!param.schema) {
92
+ throw new OpenApiToolError(`${where}: parameter ${param.name} declares no schema (content-typed parameters are not supported)`);
93
+ }
94
+ if (properties[param.name]) {
95
+ throw new OpenApiToolError(`${where}: parameter ${param.name} is both a path and a query parameter`);
96
+ }
97
+ const schema = toInputSchema(param.schema, resolver, where);
98
+ if (param.description && schema.description === undefined)
99
+ schema.description = param.description;
100
+ properties[param.name] = schema;
101
+ if (param.in === 'path' || param.required)
102
+ required.push(param.name);
103
+ if (param.in === 'path') {
104
+ if (param.style !== undefined && param.style !== 'simple') {
105
+ throw new OpenApiToolError(`${where}: path parameter ${param.name} uses style ${param.style}; only simple is supported`);
106
+ }
107
+ placements.set(param.name, { in: 'path', name: param.name });
108
+ }
109
+ else {
110
+ const style = (param.style ?? 'form');
111
+ if (!QUERY_STYLES.has(style))
112
+ throw new OpenApiToolError(`${where}: query parameter ${param.name} uses style ${style}, which is not supported`);
113
+ placements.set(param.name, { in: 'query', name: param.name, style, explode: param.explode ?? style === 'form' });
114
+ }
115
+ }
116
+ if (requestBody) {
117
+ const mediaType = jsonMediaType(requestBody.content);
118
+ if (!mediaType) {
119
+ const types = Object.keys(requestBody.content ?? {});
120
+ throw new OpenApiToolError(`${where}: its request body is ${types.join(', ') || 'undeclared'}; a tool sends JSON only`);
121
+ }
122
+ const bodySchema = toInputSchema(requestBody.content[mediaType].schema ?? {}, resolver, where);
123
+ const fields = bodySchema.properties;
124
+ const closedObject = bodySchema.type === 'object' &&
125
+ fields !== undefined &&
126
+ (bodySchema.additionalProperties === undefined || bodySchema.additionalProperties === false) &&
127
+ !['allOf', 'anyOf', 'oneOf', 'not', 'if', 'patternProperties', 'dependentSchemas'].some((k) => k in bodySchema);
128
+ const collides = closedObject && Object.keys(fields).some((name) => name in properties || name === 'body');
129
+ if (closedObject && !collides) {
130
+ // A closed object body's fields sit beside the parameters.
131
+ for (const [name, schema] of Object.entries(fields)) {
132
+ properties[name] = schema;
133
+ placements.set(name, { in: 'bodyField', name });
134
+ }
135
+ for (const name of bodySchema.required ?? [])
136
+ if (!required.includes(name))
137
+ required.push(name);
138
+ }
139
+ else {
140
+ if (properties.body)
141
+ throw new OpenApiToolError(`${where}: a parameter is named "body", which its request body needs`);
142
+ if (requestBody.description && bodySchema.description === undefined)
143
+ bodySchema.description = requestBody.description;
144
+ properties.body = bodySchema;
145
+ placements.set('body', { in: 'body' });
146
+ if (requestBody.required)
147
+ required.push('body');
148
+ }
149
+ }
150
+ return {
151
+ schema: {
152
+ type: 'object',
153
+ properties,
154
+ ...(required.length > 0 ? { required } : {}),
155
+ // A tool accepts exactly what its operation declares (ADR-0182 §5).
156
+ additionalProperties: false,
157
+ },
158
+ placements,
159
+ requiredHeaders,
160
+ };
161
+ }
162
+ function checkSecurity(security, schemes, where) {
163
+ if (security === undefined) {
164
+ throw new OpenApiToolError(`${where}: an exposed operation declares its security requirement (operation or document \`security\`; [] for a public one)`);
165
+ }
166
+ if (!Array.isArray(security))
167
+ throw new OpenApiToolError(`${where}: security is a list of requirement objects`);
168
+ return security.map((requirement) => {
169
+ if (!requirement || typeof requirement !== 'object' || Array.isArray(requirement)) {
170
+ throw new OpenApiToolError(`${where}: security is a list of requirement objects`);
171
+ }
172
+ const out = {};
173
+ for (const [scheme, scopes] of Object.entries(requirement)) {
174
+ if (!schemes || !Object.prototype.hasOwnProperty.call(schemes, scheme)) {
175
+ throw new OpenApiToolError(`${where}: security names scheme "${scheme}", which components.securitySchemes does not declare`);
176
+ }
177
+ if (!Array.isArray(scopes) || scopes.some((s) => typeof s !== 'string')) {
178
+ throw new OpenApiToolError(`${where}: security scheme "${scheme}" lists its scopes as strings`);
179
+ }
180
+ out[scheme] = [...scopes];
181
+ }
182
+ return out;
183
+ });
184
+ }
185
+ function bindOperation(raw, effect, options, where) {
186
+ if (raw === undefined)
187
+ return null;
188
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
189
+ throw new OpenApiToolError(`${where}: x-async-binding is an object`);
190
+ const binding = raw;
191
+ if (typeof binding.event !== 'string' || binding.event.trim() === '') {
192
+ throw new OpenApiToolError(`${where}: x-async-binding.event names the declared completion the job ends with`);
193
+ }
194
+ const kind = effectKind(effect);
195
+ if (kind !== 'job' && kind !== 'transaction') {
196
+ throw new OpenApiToolError(`${where}: x-async-binding waits on a job, but its effect is ${kind}; declare effect job`);
197
+ }
198
+ if (!options.events) {
199
+ throw new OpenApiToolError(`${where} waits on '${binding.event}', but no event declarations were given (OpenApiToolsOptions.events)`);
200
+ }
201
+ for (const key of ['failure', 'correlation', 'idField']) {
202
+ if (binding[key] !== undefined && typeof binding[key] !== 'string') {
203
+ throw new OpenApiToolError(`${where}: x-async-binding.${key} is ${key === 'failure' ? 'an event' : 'a field'} name`);
204
+ }
205
+ }
206
+ const effectTimeout = typeof effect === 'object' && 'timeoutMs' in effect ? effect.timeoutMs : undefined;
207
+ let bound;
208
+ try {
209
+ bound = bindAsyncTool(options.events, {
210
+ usedBy: where,
211
+ completion: binding.event,
212
+ ...(typeof binding.failure === 'string' ? { failure: binding.failure } : {}),
213
+ ...(typeof binding.correlation === 'string' ? { correlation: binding.correlation } : {}),
214
+ timeoutMs: parseWaitTimeout(where, 'x-async-binding.timeout', binding.timeout, effectTimeout ?? 60_000),
215
+ });
216
+ }
217
+ catch (err) {
218
+ throw new OpenApiToolError(err instanceof Error ? err.message.replace(/^\[agent-sdk\] /, '') : String(err));
219
+ }
220
+ return { bound, idField: typeof binding.idField === 'string' ? binding.idField : bound.binding.correlation };
221
+ }
222
+ function checkOptions(options) {
223
+ if (!options || typeof options.actAs !== 'function') {
224
+ throw new OpenApiToolError('loadOpenApiTools: actAs is required: it names who each call acts as, and has no default');
225
+ }
226
+ if (options.audience !== 'agents' && options.audience !== 'pa') {
227
+ throw new OpenApiToolError('loadOpenApiTools: audience is "agents" or "pa"');
228
+ }
229
+ let url;
230
+ try {
231
+ url = new URL(options.baseUrl);
232
+ }
233
+ catch {
234
+ throw new OpenApiToolError(`loadOpenApiTools: baseUrl "${String(options.baseUrl)}" is not an absolute http(s) URL`);
235
+ }
236
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
237
+ throw new OpenApiToolError(`loadOpenApiTools: baseUrl "${options.baseUrl}" is not an absolute http(s) URL`);
238
+ }
239
+ return options.baseUrl.replace(/\/+$/, '');
240
+ }
241
+ /**
242
+ * Turn an OpenAPI 3 document into tools. Throws `OpenApiToolError`, naming the
243
+ * operation, for anything it refuses.
244
+ */
245
+ export function loadOpenApiTools(document, options) {
246
+ const baseUrl = checkOptions(options);
247
+ if (!document || typeof document.openapi !== 'string' || !/^3\.\d+(\.\d+)?/.test(document.openapi)) {
248
+ throw new OpenApiToolError('loadOpenApiTools: this is not an OpenAPI 3 document (its `openapi` field is not 3.x)');
249
+ }
250
+ const resolver = createResolver(document);
251
+ const fetchImpl = options.fetch ?? globalThis.fetch;
252
+ const { events, waiter } = options;
253
+ const schemes = document.components?.securitySchemes;
254
+ const tools = [];
255
+ const names = new Map();
256
+ for (const [path, pathItem] of Object.entries(document.paths ?? {})) {
257
+ for (const method of HTTP_METHODS) {
258
+ const operation = pathItem?.[method];
259
+ if (!operation)
260
+ continue;
261
+ const where = describeOperation(method, path, operation.operationId);
262
+ const exposure = readAgentExposure(operation['x-agent'], { method, operationId: operation.operationId }, where);
263
+ if (!exposure?.expose)
264
+ continue;
265
+ const operationId = operation.operationId;
266
+ if (!operationId)
267
+ throw new OpenApiToolError(`${where}: an exposed operation needs an operationId, its tool name`);
268
+ if (!TOOL_NAME.test(operationId)) {
269
+ throw new OpenApiToolError(`${where}: operationId "${operationId}" is not a tool name (letters, digits, _ and -, at most 64)`);
270
+ }
271
+ const clash = names.get(operationId);
272
+ if (clash)
273
+ throw new OpenApiToolError(`${where}: operationId "${operationId}" is also ${clash}`);
274
+ names.set(operationId, describeOperation(method, path));
275
+ const security = checkSecurity(operation.security ?? document.security, schemes, where);
276
+ const parameters = mergedParameters(pathItem.parameters, operation.parameters, resolver, where);
277
+ const requestBody = operation.requestBody ? resolver.deref(operation.requestBody, where) : undefined;
278
+ const input = buildInput(path, parameters, requestBody, resolver, where);
279
+ const effect = exposure.effect;
280
+ const asyncOperation = bindOperation(operation['x-async-binding'], effect, options, where);
281
+ const bound = asyncOperation?.bound;
282
+ if (options.audience === 'pa' && !exposure.pa)
283
+ continue;
284
+ const isRead = effectAccess(effect) === 'read';
285
+ // The worker's quota reads this flag: a read is side-effect free.
286
+ if (isRead)
287
+ input.schema.sideEffects = false;
288
+ const summary = operation.summary?.trim();
289
+ const detail = operation.description?.trim();
290
+ const description = [
291
+ [summary, detail && detail !== summary ? detail : undefined].filter(Boolean).join('\n\n') || operationId,
292
+ ...effectSentences(effect, exposure.destructive, exposure.consequence),
293
+ // Promise the event only when the tool will actually wait for it.
294
+ ...(bound && options.waiter
295
+ ? [`It waits for ${bound.binding.completion}, and returns the finished result, or why the job failed.`]
296
+ : []),
297
+ ].join(' ');
298
+ const plan = {
299
+ operationId,
300
+ method,
301
+ path,
302
+ baseUrl,
303
+ placements: input.placements,
304
+ requiredHeaders: input.requiredHeaders,
305
+ actAs: options.actAs,
306
+ fetch: fetchImpl,
307
+ };
308
+ const irreversible = effectKind(effect) === 'transaction';
309
+ tools.push({
310
+ name: operationId,
311
+ kind: 'backend',
312
+ description,
313
+ inputSchema: input.schema,
314
+ effect,
315
+ destructive: exposure.destructive,
316
+ // The approval card's title and consequence come from the operation (ADR-0228 §2.2.2).
317
+ title: summary || operationId,
318
+ ...(exposure.consequence ? { consequence: exposure.consequence } : {}),
319
+ operation: {
320
+ operationId,
321
+ method,
322
+ path,
323
+ title: summary || operationId,
324
+ security,
325
+ ...(bound
326
+ ? {
327
+ async: {
328
+ completion: bound.binding.completion,
329
+ ...(bound.binding.failure ? { failure: bound.binding.failure } : {}),
330
+ correlation: bound.binding.correlation,
331
+ idField: asyncOperation.idField,
332
+ timeoutMs: bound.timeoutMs,
333
+ },
334
+ }
335
+ : {}),
336
+ },
337
+ async execute(args, ctx) {
338
+ // An irreversible act runs only on the person's approval of this exact call
339
+ // (ADR-0228). The worker runs it with that approval once the person gave it;
340
+ // any other runner (an MCP server, a host calling the tool itself) has none.
341
+ if (irreversible && !ctx.approval) {
342
+ return {
343
+ success: false,
344
+ error: `"${operationId}" is irreversible: it runs only on the person’s approval of this exact call, and this call has none`,
345
+ data: { code: 'APPROVAL_REQUIRED' },
346
+ };
347
+ }
348
+ const result = await executeOperation(plan, args, ctx);
349
+ if (!bound || !waiter || !result.success)
350
+ return result;
351
+ // The job started: wait for its declared completion or failure.
352
+ const dispatch = result.data && typeof result.data === 'object' && !Array.isArray(result.data) ? result.data : {};
353
+ const settled = await awaitAsyncTool(events, waiter, bound, dispatch[asyncOperation.idField], ctx.abortSignal);
354
+ return asyncToolResult(dispatch, settled);
355
+ },
356
+ });
357
+ }
358
+ }
359
+ return tools;
360
+ }
361
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/openapi/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAqB,MAAM,mBAAmB,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAuB,MAAM,2BAA2B,CAAC;AAElI,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,aAAa,GASd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAsD,MAAM,eAAe,CAAC;AACrG,OAAO,EAAE,iBAAiB,EAAsB,MAAM,cAAc,CAAC;AA+CrE,uDAAuD;AACvD,MAAM,SAAS,GAAG,uBAAuB,CAAC;AAC1C,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,gBAAgB,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC,CAAC;AAExF,SAAS,iBAAiB,CAAC,MAAkB,EAAE,IAAY,EAAE,WAAoB;IAC/E,OAAO,GAAG,MAAM,CAAC,WAAW,EAAE,IAAI,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,WAAW,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACpF,CAAC;AAED,SAAS,aAAa,CAAC,OAA4C;IACjE,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gDAAgD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAChH,CAAC;AAED,iHAAiH;AACjH,SAAS,gBAAgB,CACvB,UAAkE,EAClE,QAAgE,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AAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;oBACvD,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO;wBAAE,OAAO,MAAM,CAAC;oBACxD,gEAAgE;oBAChE,MAAM,QAAQ,GACZ,MAAM,CAAC,IAAI,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,MAAM,CAAC,IAAgC,CAAC,CAAC,CAAC,EAAE,CAAC;oBAChI,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,MAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,cAAe,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;oBACjH,OAAO,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAC5C,CAAC;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * `x-agent`: how an operation opts in as an agent tool (ADR-0181 §3, ADR-0227 §2.1).
3
+ *
4
+ * ```yaml
5
+ * x-agent:
6
+ * expose: true # without it, the operation is not a tool
7
+ * effect: mutate # ADR-0226 §2.6: view | file | mutate | job | transaction, or its object form
8
+ * destructive: true # optional, on a write: removes or replaces something the person made
9
+ * consequence: "..." # optional: what happens, for the tool's description and an approval's preview
10
+ * pa: true # optional: the product's own assistant may call it; only on a read
11
+ * ```
12
+ *
13
+ * Every field is checked, on every operation that carries `x-agent`, exposed or not.
14
+ */
15
+ import { type ActionEffect, type ActionEffectKind } from '@ouispec/bindings';
16
+ import { type HttpMethod } from './document.js';
17
+ export interface AgentExposure {
18
+ expose: boolean;
19
+ effect?: ActionEffect;
20
+ destructive: boolean;
21
+ consequence?: string;
22
+ pa: boolean;
23
+ }
24
+ /** The effects an API operation can have. The others (selection, navigate, open, edit) only a page has. */
25
+ export declare const API_OPERATION_EFFECTS: readonly ActionEffectKind[];
26
+ /**
27
+ * Read and check an operation's `x-agent`. Returns null when it has none.
28
+ * `where` names the operation in every refusal.
29
+ */
30
+ export declare function readAgentExposure(raw: unknown, op: {
31
+ method: HttpMethod;
32
+ operationId?: string;
33
+ }, where: string): AgentExposure | null;
34
+ //# sourceMappingURL=x-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x-agent.d.ts","sourceRoot":"","sources":["../../src/openapi/x-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAA2C,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACtH,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAElE,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,OAAO,CAAC;CACb;AAID,2GAA2G;AAC3G,eAAO,MAAM,qBAAqB,EAAE,SAAS,gBAAgB,EAAqD,CAAC;AAiCnH;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,OAAO,EACZ,EAAE,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,EAChD,KAAK,EAAE,MAAM,GACZ,aAAa,GAAG,IAAI,CA8CtB"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * `x-agent`: how an operation opts in as an agent tool (ADR-0181 §3, ADR-0227 §2.1).
3
+ *
4
+ * ```yaml
5
+ * x-agent:
6
+ * expose: true # without it, the operation is not a tool
7
+ * effect: mutate # ADR-0226 §2.6: view | file | mutate | job | transaction, or its object form
8
+ * destructive: true # optional, on a write: removes or replaces something the person made
9
+ * consequence: "..." # optional: what happens, for the tool's description and an approval's preview
10
+ * pa: true # optional: the product's own assistant may call it; only on a read
11
+ * ```
12
+ *
13
+ * Every field is checked, on every operation that carries `x-agent`, exposed or not.
14
+ */
15
+ import { effectAccess, effectKind, effectProblem } from '@ouispec/bindings';
16
+ import { OpenApiToolError } from './document.js';
17
+ const KEYS = new Set(['expose', 'effect', 'destructive', 'consequence', 'pa']);
18
+ /** The effects an API operation can have. The others (selection, navigate, open, edit) only a page has. */
19
+ export const API_OPERATION_EFFECTS = ['view', 'file', 'mutate', 'job', 'transaction'];
20
+ /** Methods that change data by definition (RFC 9110): a read-only effect on one is a mistake. */
21
+ const WRITE_METHODS = new Set(['put', 'patch', 'delete']);
22
+ /**
23
+ * The effect as the tool carries it. A `mutate` or `transaction` is through this
24
+ * operation, so its `operation` is filled in; one naming another operation is refused.
25
+ */
26
+ function readEffect(value, operationId, where) {
27
+ let effect = value;
28
+ if (effect === 'mutate' || effect === 'transaction' || effect === 'job')
29
+ effect = { kind: effect };
30
+ if (effect && typeof effect === 'object' && !Array.isArray(effect)) {
31
+ const e = { ...effect };
32
+ if (e.kind === 'mutate' || e.kind === 'transaction') {
33
+ if (e.operation !== undefined && e.operation !== operationId) {
34
+ throw new OpenApiToolError(`${where}: x-agent.effect names operation "${String(e.operation)}"; an operation's effect is its own`);
35
+ }
36
+ if (operationId)
37
+ e.operation = operationId;
38
+ }
39
+ effect = e;
40
+ }
41
+ const problem = effectProblem(effect);
42
+ if (problem)
43
+ throw new OpenApiToolError(`${where}: x-agent.effect: ${problem}`);
44
+ const kind = effectKind(effect);
45
+ if (!API_OPERATION_EFFECTS.includes(kind)) {
46
+ throw new OpenApiToolError(`${where}: x-agent.effect ${kind} is a page's effect; an API operation's effect is one of ${API_OPERATION_EFFECTS.join(', ')}`);
47
+ }
48
+ return effect;
49
+ }
50
+ /**
51
+ * Read and check an operation's `x-agent`. Returns null when it has none.
52
+ * `where` names the operation in every refusal.
53
+ */
54
+ export function readAgentExposure(raw, op, where) {
55
+ if (raw === undefined)
56
+ return null;
57
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
58
+ throw new OpenApiToolError(`${where}: x-agent is an object`);
59
+ const x = raw;
60
+ for (const key of Object.keys(x)) {
61
+ if (!KEYS.has(key))
62
+ throw new OpenApiToolError(`${where}: x-agent has an unknown key "${key}" (${[...KEYS].join(', ')})`);
63
+ }
64
+ const flag = (key) => {
65
+ if (x[key] === undefined)
66
+ return false;
67
+ if (typeof x[key] !== 'boolean')
68
+ throw new OpenApiToolError(`${where}: x-agent.${key} is true or false`);
69
+ return x[key];
70
+ };
71
+ const expose = flag('expose');
72
+ const destructive = flag('destructive');
73
+ const pa = flag('pa');
74
+ if (x.consequence !== undefined && (typeof x.consequence !== 'string' || x.consequence.trim() === '')) {
75
+ throw new OpenApiToolError(`${where}: x-agent.consequence is a non-empty sentence`);
76
+ }
77
+ if (expose && x.effect === undefined)
78
+ throw new OpenApiToolError(`${where}: x-agent.effect is required on an exposed operation`);
79
+ const effect = x.effect === undefined ? undefined : readEffect(x.effect, op.operationId, where);
80
+ const access = effectAccess(effect);
81
+ if (destructive && access !== 'write') {
82
+ throw new OpenApiToolError(`${where}: x-agent.destructive applies only to a write; this operation's effect is read-only`);
83
+ }
84
+ if (effect && access === 'read' && WRITE_METHODS.has(op.method)) {
85
+ throw new OpenApiToolError(`${where}: effect ${effectKind(effect)} is read-only, but ${op.method.toUpperCase()} changes data; declare what it changes`);
86
+ }
87
+ if (pa) {
88
+ if (!expose)
89
+ throw new OpenApiToolError(`${where}: x-agent.pa needs expose: true`);
90
+ if (access !== 'read') {
91
+ throw new OpenApiToolError(`${where}: x-agent.pa is allowed only on a read-only operation (effect view); this one is ${effectKind(effect)}, a write`);
92
+ }
93
+ }
94
+ return {
95
+ expose,
96
+ ...(effect !== undefined ? { effect } : {}),
97
+ destructive,
98
+ ...(typeof x.consequence === 'string' ? { consequence: x.consequence } : {}),
99
+ pa,
100
+ };
101
+ }
102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CAAC,CAAC;IAC5H,CAAC;IACD,IAAI,MAAM,IAAI,MAAM,KAAK,MAAM,IAAI,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,gBAAgB,CACxB,GAAG,KAAK,YAAY,UAAU,CAAC,MAAM,CAAC,sBAAsB,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,wCAAwC,CAC5H,CAAC;IACJ,CAAC;IACD,IAAI,EAAE,EAAE,CAAC;QACP,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,gBAAgB,CAAC,GAAG,KAAK,iCAAiC,CAAC,CAAC;QACnF,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;YACtB,MAAM,IAAI,gBAAgB,CACxB,GAAG,KAAK,oFAAoF,UAAU,CAAC,MAAO,CAAC,WAAW,CAC3H,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO;QACL,MAAM;QACN,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,WAAW;QACX,GAAG,CAAC,OAAO,CAAC,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,EAAE;KACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { AgentWorkerConfig, AgentTurnInput, AgentTurnResult } from './types.js';
2
+ /**
3
+ * Run a complete agent turn using the Vercel AI SDK.
4
+ *
5
+ * A turn runs in one or more segments. Each segment is one `streamText` call
6
+ * with a fixed tool set. When a UI action changes what the client's page
7
+ * offers (navigating is the common case), the segment ends and the turn
8
+ * continues in a new one whose tools are the new page's (ADR-0209 D3). The
9
+ * round cap counts across segments.
10
+ */
11
+ export declare function runAgentTurn(config: AgentWorkerConfig, input: AgentTurnInput): Promise<AgentTurnResult>;
12
+ //# sourceMappingURL=orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAmC,MAAM,YAAY,CAAC;AAiDtH;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,iBAAiB,EACzB,KAAK,EAAE,cAAc,GACpB,OAAO,CAAC,eAAe,CAAC,CAkyB1B"}