@every-app/sdk 0.3.0-rc.11 → 0.3.0-rc.12

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 (66) hide show
  1. package/README.md +6 -4
  2. package/dist/cloudflare/worker.d.ts +1 -1
  3. package/dist/cloudflare/worker.d.ts.map +1 -1
  4. package/dist/cloudflare/worker.js +1 -2
  5. package/dist/internal/aiDefault.d.ts +32 -76
  6. package/dist/internal/aiDefault.d.ts.map +1 -1
  7. package/dist/internal/aiDefault.js +41 -144
  8. package/dist/internal/appSettings.d.ts +14 -17
  9. package/dist/internal/appSettings.d.ts.map +1 -1
  10. package/dist/internal/appSettings.js +2 -16
  11. package/dist/internal/capabilities.d.ts +9 -8
  12. package/dist/internal/capabilities.d.ts.map +1 -1
  13. package/dist/internal/capabilities.js +2 -2
  14. package/dist/internal/catalog/commerce.js +1 -1
  15. package/dist/internal/gatewaySettings.d.ts +2 -2
  16. package/dist/internal/gatewaySettings.d.ts.map +1 -1
  17. package/dist/internal/gatewaySettings.js +0 -6
  18. package/dist/internal/protocol.d.ts +5 -24
  19. package/dist/internal/protocol.d.ts.map +1 -1
  20. package/dist/internal/protocol.js +0 -19
  21. package/dist/internal/remoteMcp.d.ts +4 -6
  22. package/dist/internal/remoteMcp.d.ts.map +1 -1
  23. package/dist/internal/remoteMcp.js +7 -10
  24. package/dist/internal/tools.d.ts +11 -7
  25. package/dist/internal/tools.d.ts.map +1 -1
  26. package/dist/internal/tools.js +8 -8
  27. package/dist/manifest.d.ts +9 -25
  28. package/dist/manifest.d.ts.map +1 -1
  29. package/dist/server/ai.d.ts +1 -93
  30. package/dist/server/ai.d.ts.map +1 -1
  31. package/dist/server/ai.js +17 -111
  32. package/dist/server/attribution.d.ts +1 -1
  33. package/dist/server/context.d.ts +12 -14
  34. package/dist/server/context.d.ts.map +1 -1
  35. package/dist/server/context.js +23 -25
  36. package/dist/server/everyApp.d.ts +4 -23
  37. package/dist/server/everyApp.d.ts.map +1 -1
  38. package/dist/server/everyApp.js +13 -46
  39. package/dist/server/gatewayFetch.d.ts +1 -1
  40. package/dist/server/gatewayFetch.js +1 -1
  41. package/dist/server/index.d.ts +3 -7
  42. package/dist/server/index.d.ts.map +1 -1
  43. package/dist/server/index.js +3 -7
  44. package/dist/server/integrationFetch.d.ts +1 -1
  45. package/dist/server/refusal.d.ts +0 -9
  46. package/dist/server/refusal.d.ts.map +1 -1
  47. package/dist/server/refusal.js +0 -22
  48. package/dist/server/tools.d.ts +11 -8
  49. package/dist/server/tools.d.ts.map +1 -1
  50. package/dist/server/tools.js +10 -4
  51. package/dist/server/toolsEndpoint.d.ts +2 -3
  52. package/dist/server/toolsEndpoint.d.ts.map +1 -1
  53. package/dist/server/toolsEndpoint.js +6 -11
  54. package/dist/testing/index.d.ts +2 -3
  55. package/dist/testing/index.d.ts.map +1 -1
  56. package/dist/testing/index.js +2 -6
  57. package/package.json +1 -1
  58. package/dist/server/aiBinding.d.ts +0 -68
  59. package/dist/server/aiBinding.d.ts.map +0 -1
  60. package/dist/server/aiBinding.js +0 -294
  61. package/dist/server/emailBinding.d.ts +0 -72
  62. package/dist/server/emailBinding.d.ts.map +0 -1
  63. package/dist/server/emailBinding.js +0 -124
  64. package/dist/server/fromMcpTools.d.ts +0 -89
  65. package/dist/server/fromMcpTools.d.ts.map +0 -1
  66. package/dist/server/fromMcpTools.js +0 -192
@@ -1,192 +0,0 @@
1
- /**
2
- * `fromMcpTools()` — an app's existing MCP tools as `defineTools()` entries.
3
- *
4
- * const tools: McpToolLike[] = [];
5
- * registerMyTools((name, config, handler) =>
6
- * tools.push({ name, ...config, handler }),
7
- * );
8
- * export default everyApp(handler, {
9
- * tools: defineTools(fromMcpTools(tools), { instructions }),
10
- * });
11
- *
12
- * Takes the shape `McpServer.registerTool(name, config, handler)` is called
13
- * with (or what a low-level server's `tools/list` returns, plus a handler),
14
- * structurally: the SDK takes no dependency on `@modelcontextprotocol/sdk`,
15
- * and a live `McpServer` keeps its registry private, so the app hands over
16
- * the list it registers from.
17
- */
18
- import { TOOL_NAME_PATTERN } from "../internal/index.js";
19
- import { ToolError, toolResult, } from "./tools.js";
20
- const JSON_SCHEMA_TARGET = "draft-2020-12";
21
- /**
22
- * Adapt MCP tools into `defineTools()` entries, keyed by tool name, to spread
23
- * beside the app's own: `defineTools({ ...fromMcpTools(list), my_tool })`.
24
- *
25
- * - `title`, `description` (the name when absent), `idempotentHint` and
26
- * `openWorldHint` carry over; risk as {@link FromMcpToolsOptions.risk}.
27
- * - A result's text blocks, joined by a blank line, are what the model
28
- * reads; `structuredContent` is sent as structured content (checked
29
- * against `outputSchema` when there is one). Other blocks are dropped.
30
- * - `isError: true` becomes a {@link ToolError} with the result's text.
31
- *
32
- * Names must already be lowercase snake_case; `defineTools()` checks them.
33
- */
34
- export function fromMcpTools(tools, options = {}) {
35
- const out = {};
36
- for (const tool of tools) {
37
- const problem = (message) => new TypeError(`fromMcpTools: tool "${tool?.name}" ${message}`);
38
- if (!tool || typeof tool.name !== "string") {
39
- throw new TypeError("fromMcpTools: every tool needs a name");
40
- }
41
- if (!TOOL_NAME_PATTERN.test(tool.name)) {
42
- throw problem("must be named in lowercase snake_case: a letter, then letters, digits or _ (at most 48 characters); rename it in the list");
43
- }
44
- if (Object.prototype.hasOwnProperty.call(out, tool.name)) {
45
- throw problem("is listed twice");
46
- }
47
- if (typeof tool.handler !== "function") {
48
- throw problem("needs a handler function");
49
- }
50
- const output = tool.outputSchema === undefined
51
- ? undefined
52
- : toToolSchema(tool.outputSchema, problem);
53
- const annotations = tool.annotations ?? {};
54
- const title = tool.title ?? annotations.title;
55
- out[tool.name] = {
56
- ...(title !== undefined ? { title } : {}),
57
- description: tool.description?.trim() ? tool.description : tool.name,
58
- risk: options.risk?.(tool) ?? defaultRisk(annotations),
59
- input: toToolSchema(tool.inputSchema ?? {}, problem),
60
- ...(output ? { output } : {}),
61
- ...(annotations.idempotentHint !== undefined
62
- ? { idempotent: annotations.idempotentHint }
63
- : {}),
64
- ...(annotations.openWorldHint !== undefined
65
- ? { openWorld: annotations.openWorldHint }
66
- : {}),
67
- handler: async (args, context) => {
68
- const extra = options.context
69
- ? await options.context(context)
70
- : context;
71
- const result = await tool.handler(args, extra);
72
- return fromCallToolResult(result);
73
- },
74
- };
75
- }
76
- return out;
77
- }
78
- function defaultRisk(annotations) {
79
- if (annotations.readOnlyHint === true)
80
- return "read";
81
- return annotations.destructiveHint === true ? "destructive" : "write";
82
- }
83
- function fromCallToolResult(result) {
84
- if (!isRecord(result)) {
85
- throw new Error("the MCP tool did not return a CallToolResult");
86
- }
87
- const text = (Array.isArray(result.content) ? result.content : [])
88
- .flatMap((part) => isRecord(part) && part.type === "text" && typeof part.text === "string"
89
- ? [part.text]
90
- : [])
91
- .join("\n\n");
92
- if (result.isError === true)
93
- throw new ToolError(text || "The tool failed.");
94
- const structured = result.structuredContent;
95
- if (isRecord(structured) && !Array.isArray(structured)) {
96
- return toolResult({ text, structured });
97
- }
98
- return text;
99
- }
100
- function isRecord(value) {
101
- return typeof value === "object" && value !== null;
102
- }
103
- function isStandardWithJson(value) {
104
- if (!isRecord(value))
105
- return false;
106
- const standard = value["~standard"];
107
- return (isRecord(standard) &&
108
- typeof standard.validate === "function" &&
109
- isRecord(standard.jsonSchema));
110
- }
111
- function isPlainToolSchema(value) {
112
- return isRecord(value.jsonSchema) && typeof value.validate === "function";
113
- }
114
- function toToolSchema(schema, problem) {
115
- if (!isRecord(schema) || Array.isArray(schema)) {
116
- throw problem("has a schema that is not an object");
117
- }
118
- if (isStandardWithJson(schema) || isPlainToolSchema(schema)) {
119
- return schema;
120
- }
121
- if ("~standard" in schema) {
122
- throw problem("has a schema that doesn't convert to JSON Schema (zod >= 4.2 does)");
123
- }
124
- const values = Object.values(schema);
125
- if (values.every((value) => isRecord(value) && "~standard" in value)) {
126
- if (!values.every(isStandardWithJson)) {
127
- throw problem("has a raw shape whose fields don't convert to JSON Schema (zod >= 4.2 does)");
128
- }
129
- return rawShapeSchema(schema);
130
- }
131
- return jsonSchemaOnly(schema);
132
- }
133
- /** A plain JSON Schema: described as is; any object passes. */
134
- function jsonSchemaOnly(jsonSchema) {
135
- return {
136
- jsonSchema,
137
- validate: (value) => isRecord(value) && !Array.isArray(value)
138
- ? { value }
139
- : { issues: [{ message: "Expected an object" }] },
140
- };
141
- }
142
- /**
143
- * `{ key: schema }` as an object schema, the way `McpServer` wraps one in
144
- * `z.object()`: unknown keys are dropped, and a field is optional when its
145
- * schema accepts `undefined`.
146
- */
147
- function rawShapeSchema(shape) {
148
- const properties = {};
149
- const required = [];
150
- for (const [key, field] of Object.entries(shape)) {
151
- const { $schema: _, ...property } = field["~standard"].jsonSchema.input({
152
- target: JSON_SCHEMA_TARGET,
153
- });
154
- properties[key] = property;
155
- const absent = field["~standard"].validate(undefined);
156
- // An async validator can't be asked here; call the field required.
157
- if (absent instanceof Promise || absent.issues)
158
- required.push(key);
159
- }
160
- return {
161
- jsonSchema: {
162
- type: "object",
163
- properties,
164
- ...(required.length > 0 ? { required } : {}),
165
- },
166
- validate: async (value) => {
167
- if (!isRecord(value) || Array.isArray(value)) {
168
- return { issues: [{ message: "Expected an object" }] };
169
- }
170
- const parsed = {};
171
- const issues = [];
172
- for (const [key, field] of Object.entries(shape)) {
173
- const result = await field["~standard"].validate(value[key]);
174
- if (result.issues) {
175
- for (const issue of result.issues) {
176
- issues.push({
177
- message: issue.message,
178
- path: [
179
- key,
180
- ...(issue.path ?? []).map((segment) => typeof segment === "object" ? segment.key : segment),
181
- ],
182
- });
183
- }
184
- }
185
- else if (key in value || result.value !== undefined) {
186
- parsed[key] = result.value;
187
- }
188
- }
189
- return issues.length > 0 ? { issues } : { value: parsed };
190
- },
191
- };
192
- }