@agentjam/sdk 0.0.0-stage → 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 (274) hide show
  1. package/README.md +181 -2
  2. package/dist/adapters/ai.d.ts +47 -0
  3. package/dist/adapters/ai.d.ts.map +1 -0
  4. package/dist/adapters/ai.js +168 -0
  5. package/dist/adapters/ai.js.map +1 -0
  6. package/dist/adapters/anthropic.d.ts +68 -0
  7. package/dist/adapters/anthropic.d.ts.map +1 -0
  8. package/dist/adapters/anthropic.js +193 -0
  9. package/dist/adapters/anthropic.js.map +1 -0
  10. package/dist/adapters/openai.d.ts +35 -0
  11. package/dist/adapters/openai.d.ts.map +1 -0
  12. package/dist/adapters/openai.js +80 -0
  13. package/dist/adapters/openai.js.map +1 -0
  14. package/dist/adapters/openaiAgents.d.ts +39 -0
  15. package/dist/adapters/openaiAgents.d.ts.map +1 -0
  16. package/dist/adapters/openaiAgents.js +152 -0
  17. package/dist/adapters/openaiAgents.js.map +1 -0
  18. package/dist/adapters/shared.d.ts +72 -0
  19. package/dist/adapters/shared.d.ts.map +1 -0
  20. package/dist/adapters/shared.js +174 -0
  21. package/dist/adapters/shared.js.map +1 -0
  22. package/dist/agent.d.ts +462 -0
  23. package/dist/agent.d.ts.map +1 -0
  24. package/dist/agent.js +1820 -0
  25. package/dist/agent.js.map +1 -0
  26. package/dist/artifacts.d.ts +79 -0
  27. package/dist/artifacts.d.ts.map +1 -0
  28. package/dist/artifacts.js +367 -0
  29. package/dist/artifacts.js.map +1 -0
  30. package/dist/attachments.d.ts +43 -0
  31. package/dist/attachments.d.ts.map +1 -0
  32. package/dist/attachments.js +69 -0
  33. package/dist/attachments.js.map +1 -0
  34. package/dist/connections.d.ts +109 -0
  35. package/dist/connections.d.ts.map +1 -0
  36. package/dist/connections.js +274 -0
  37. package/dist/connections.js.map +1 -0
  38. package/dist/content.d.ts +36 -0
  39. package/dist/content.d.ts.map +1 -0
  40. package/dist/content.js +21 -0
  41. package/dist/content.js.map +1 -0
  42. package/dist/cron.d.ts +31 -0
  43. package/dist/cron.d.ts.map +1 -0
  44. package/dist/cron.js +93 -0
  45. package/dist/cron.js.map +1 -0
  46. package/dist/errors.d.ts +227 -0
  47. package/dist/errors.d.ts.map +1 -0
  48. package/dist/errors.js +253 -0
  49. package/dist/errors.js.map +1 -0
  50. package/dist/events.d.ts +57 -0
  51. package/dist/events.d.ts.map +1 -0
  52. package/dist/events.js +24 -0
  53. package/dist/events.js.map +1 -0
  54. package/dist/idempotency.d.ts +21 -0
  55. package/dist/idempotency.d.ts.map +1 -0
  56. package/dist/idempotency.js +46 -0
  57. package/dist/idempotency.js.map +1 -0
  58. package/dist/index.d.ts +44 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +18 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/inputs.d.ts +22 -0
  63. package/dist/inputs.d.ts.map +1 -0
  64. package/dist/inputs.js +72 -0
  65. package/dist/inputs.js.map +1 -0
  66. package/dist/mpp.d.ts +76 -0
  67. package/dist/mpp.d.ts.map +1 -0
  68. package/dist/mpp.js +113 -0
  69. package/dist/mpp.js.map +1 -0
  70. package/dist/oauth.d.ts +3 -0
  71. package/dist/oauth.d.ts.map +1 -0
  72. package/dist/oauth.js +2 -0
  73. package/dist/oauth.js.map +1 -0
  74. package/dist/oauthCallbacks.d.ts +2 -0
  75. package/dist/oauthCallbacks.d.ts.map +1 -0
  76. package/dist/oauthCallbacks.js +58 -0
  77. package/dist/oauthCallbacks.js.map +1 -0
  78. package/dist/platforms/datadog.d.ts +10 -0
  79. package/dist/platforms/datadog.d.ts.map +1 -0
  80. package/dist/platforms/datadog.js +15 -0
  81. package/dist/platforms/datadog.js.map +1 -0
  82. package/dist/platforms/github.d.ts +181 -0
  83. package/dist/platforms/github.d.ts.map +1 -0
  84. package/dist/platforms/github.js +468 -0
  85. package/dist/platforms/github.js.map +1 -0
  86. package/dist/platforms/google.d.ts +19 -0
  87. package/dist/platforms/google.d.ts.map +1 -0
  88. package/dist/platforms/google.js +70 -0
  89. package/dist/platforms/google.js.map +1 -0
  90. package/dist/platforms/grafana.d.ts +10 -0
  91. package/dist/platforms/grafana.d.ts.map +1 -0
  92. package/dist/platforms/grafana.js +14 -0
  93. package/dist/platforms/grafana.js.map +1 -0
  94. package/dist/platforms/posthog.d.ts +10 -0
  95. package/dist/platforms/posthog.d.ts.map +1 -0
  96. package/dist/platforms/posthog.js +14 -0
  97. package/dist/platforms/posthog.js.map +1 -0
  98. package/dist/platforms/presets.d.ts +34 -0
  99. package/dist/platforms/presets.d.ts.map +1 -0
  100. package/dist/platforms/presets.js +36 -0
  101. package/dist/platforms/presets.js.map +1 -0
  102. package/dist/platforms/sentry.d.ts +79 -0
  103. package/dist/platforms/sentry.d.ts.map +1 -0
  104. package/dist/platforms/sentry.js +124 -0
  105. package/dist/platforms/sentry.js.map +1 -0
  106. package/dist/platforms/slack.d.ts +101 -0
  107. package/dist/platforms/slack.d.ts.map +1 -0
  108. package/dist/platforms/slack.js +309 -0
  109. package/dist/platforms/slack.js.map +1 -0
  110. package/dist/platforms/splunk.d.ts +10 -0
  111. package/dist/platforms/splunk.d.ts.map +1 -0
  112. package/dist/platforms/splunk.js +14 -0
  113. package/dist/platforms/splunk.js.map +1 -0
  114. package/dist/polling.d.ts +2 -0
  115. package/dist/polling.d.ts.map +1 -0
  116. package/dist/polling.js +66 -0
  117. package/dist/polling.js.map +1 -0
  118. package/dist/profile.d.ts +60 -0
  119. package/dist/profile.d.ts.map +1 -0
  120. package/dist/profile.js +119 -0
  121. package/dist/profile.js.map +1 -0
  122. package/dist/protocol.d.ts +474 -0
  123. package/dist/protocol.d.ts.map +1 -0
  124. package/dist/protocol.js +2 -0
  125. package/dist/protocol.js.map +1 -0
  126. package/dist/providers.d.ts +113 -0
  127. package/dist/providers.d.ts.map +1 -0
  128. package/dist/providers.js +98 -0
  129. package/dist/providers.js.map +1 -0
  130. package/dist/recaps.d.ts +10 -0
  131. package/dist/recaps.d.ts.map +1 -0
  132. package/dist/recaps.js +49 -0
  133. package/dist/recaps.js.map +1 -0
  134. package/dist/relay/chains.d.ts +62 -0
  135. package/dist/relay/chains.d.ts.map +1 -0
  136. package/dist/relay/chains.js +150 -0
  137. package/dist/relay/chains.js.map +1 -0
  138. package/dist/relay/credentials.d.ts +25 -0
  139. package/dist/relay/credentials.d.ts.map +1 -0
  140. package/dist/relay/credentials.js +234 -0
  141. package/dist/relay/credentials.js.map +1 -0
  142. package/dist/relay/endpoints.d.ts +13 -0
  143. package/dist/relay/endpoints.d.ts.map +1 -0
  144. package/dist/relay/endpoints.js +13 -0
  145. package/dist/relay/endpoints.js.map +1 -0
  146. package/dist/relay/frames.d.ts +193 -0
  147. package/dist/relay/frames.d.ts.map +1 -0
  148. package/dist/relay/frames.js +161 -0
  149. package/dist/relay/frames.js.map +1 -0
  150. package/dist/relay/grants.d.ts +158 -0
  151. package/dist/relay/grants.d.ts.map +1 -0
  152. package/dist/relay/grants.js +2 -0
  153. package/dist/relay/grants.js.map +1 -0
  154. package/dist/relay/guestStore.d.ts +37 -0
  155. package/dist/relay/guestStore.d.ts.map +1 -0
  156. package/dist/relay/guestStore.js +61 -0
  157. package/dist/relay/guestStore.js.map +1 -0
  158. package/dist/relay/guests.d.ts +7 -0
  159. package/dist/relay/guests.d.ts.map +1 -0
  160. package/dist/relay/guests.js +30 -0
  161. package/dist/relay/guests.js.map +1 -0
  162. package/dist/relay/memory.d.ts +60 -0
  163. package/dist/relay/memory.d.ts.map +1 -0
  164. package/dist/relay/memory.js +334 -0
  165. package/dist/relay/memory.js.map +1 -0
  166. package/dist/relay/payments.d.ts +43 -0
  167. package/dist/relay/payments.d.ts.map +1 -0
  168. package/dist/relay/payments.js +115 -0
  169. package/dist/relay/payments.js.map +1 -0
  170. package/dist/relay/profiles.d.ts +10 -0
  171. package/dist/relay/profiles.d.ts.map +1 -0
  172. package/dist/relay/profiles.js +43 -0
  173. package/dist/relay/profiles.js.map +1 -0
  174. package/dist/relay/relay.d.ts +133 -0
  175. package/dist/relay/relay.d.ts.map +1 -0
  176. package/dist/relay/relay.js +2 -0
  177. package/dist/relay/relay.js.map +1 -0
  178. package/dist/relay/remote.d.ts +39 -0
  179. package/dist/relay/remote.d.ts.map +1 -0
  180. package/dist/relay/remote.js +492 -0
  181. package/dist/relay/remote.js.map +1 -0
  182. package/dist/relay/revisions.d.ts +13 -0
  183. package/dist/relay/revisions.d.ts.map +1 -0
  184. package/dist/relay/revisions.js +34 -0
  185. package/dist/relay/revisions.js.map +1 -0
  186. package/dist/relay/schedules.d.ts +41 -0
  187. package/dist/relay/schedules.d.ts.map +1 -0
  188. package/dist/relay/schedules.js +217 -0
  189. package/dist/relay/schedules.js.map +1 -0
  190. package/dist/relay/secrets.d.ts +14 -0
  191. package/dist/relay/secrets.d.ts.map +1 -0
  192. package/dist/relay/secrets.js +30 -0
  193. package/dist/relay/secrets.js.map +1 -0
  194. package/dist/relay/sessions.d.ts +59 -0
  195. package/dist/relay/sessions.d.ts.map +1 -0
  196. package/dist/relay/sessions.js +282 -0
  197. package/dist/relay/sessions.js.map +1 -0
  198. package/dist/relay/uploads.d.ts +15 -0
  199. package/dist/relay/uploads.d.ts.map +1 -0
  200. package/dist/relay/uploads.js +55 -0
  201. package/dist/relay/uploads.js.map +1 -0
  202. package/dist/requests.d.ts +22 -0
  203. package/dist/requests.d.ts.map +1 -0
  204. package/dist/requests.js +64 -0
  205. package/dist/requests.js.map +1 -0
  206. package/dist/screening.d.ts +93 -0
  207. package/dist/screening.d.ts.map +1 -0
  208. package/dist/screening.js +176 -0
  209. package/dist/screening.js.map +1 -0
  210. package/dist/secrets.d.ts +38 -0
  211. package/dist/secrets.d.ts.map +1 -0
  212. package/dist/secrets.js +162 -0
  213. package/dist/secrets.js.map +1 -0
  214. package/dist/skills.d.ts +11 -0
  215. package/dist/skills.d.ts.map +1 -0
  216. package/dist/skills.js +55 -0
  217. package/dist/skills.js.map +1 -0
  218. package/dist/stripe.d.ts +10 -0
  219. package/dist/stripe.d.ts.map +1 -0
  220. package/dist/stripe.js +51 -0
  221. package/dist/stripe.js.map +1 -0
  222. package/dist/tasks/access.d.ts +35 -0
  223. package/dist/tasks/access.d.ts.map +1 -0
  224. package/dist/tasks/access.js +101 -0
  225. package/dist/tasks/access.js.map +1 -0
  226. package/dist/tasks/incoming.d.ts +333 -0
  227. package/dist/tasks/incoming.d.ts.map +1 -0
  228. package/dist/tasks/incoming.js +354 -0
  229. package/dist/tasks/incoming.js.map +1 -0
  230. package/dist/tasks/outgoing.d.ts +137 -0
  231. package/dist/tasks/outgoing.d.ts.map +1 -0
  232. package/dist/tasks/outgoing.js +233 -0
  233. package/dist/tasks/outgoing.js.map +1 -0
  234. package/dist/tasks/scheduled.d.ts +76 -0
  235. package/dist/tasks/scheduled.d.ts.map +1 -0
  236. package/dist/tasks/scheduled.js +110 -0
  237. package/dist/tasks/scheduled.js.map +1 -0
  238. package/dist/tasks/triggers.d.ts +47 -0
  239. package/dist/tasks/triggers.d.ts.map +1 -0
  240. package/dist/tasks/triggers.js +149 -0
  241. package/dist/tasks/triggers.js.map +1 -0
  242. package/dist/tasks/watches.d.ts +13 -0
  243. package/dist/tasks/watches.d.ts.map +1 -0
  244. package/dist/tasks/watches.js +54 -0
  245. package/dist/tasks/watches.js.map +1 -0
  246. package/dist/tools.d.ts +85 -0
  247. package/dist/tools.d.ts.map +1 -0
  248. package/dist/tools.js +627 -0
  249. package/dist/tools.js.map +1 -0
  250. package/dist/types.d.ts +926 -0
  251. package/dist/types.d.ts.map +1 -0
  252. package/dist/types.js +2 -0
  253. package/dist/types.js.map +1 -0
  254. package/dist/vaults/local.d.ts +54 -0
  255. package/dist/vaults/local.d.ts.map +1 -0
  256. package/dist/vaults/local.js +362 -0
  257. package/dist/vaults/local.js.map +1 -0
  258. package/dist/vaults/remote.d.ts +78 -0
  259. package/dist/vaults/remote.d.ts.map +1 -0
  260. package/dist/vaults/remote.js +295 -0
  261. package/dist/vaults/remote.js.map +1 -0
  262. package/dist/vaults/vault.d.ts +69 -0
  263. package/dist/vaults/vault.d.ts.map +1 -0
  264. package/dist/vaults/vault.js +19 -0
  265. package/dist/vaults/vault.js.map +1 -0
  266. package/dist/verdicts.d.ts +15 -0
  267. package/dist/verdicts.d.ts.map +1 -0
  268. package/dist/verdicts.js +17 -0
  269. package/dist/verdicts.js.map +1 -0
  270. package/dist/watermarks.d.ts +29 -0
  271. package/dist/watermarks.d.ts.map +1 -0
  272. package/dist/watermarks.js +11 -0
  273. package/dist/watermarks.js.map +1 -0
  274. package/package.json +152 -3
@@ -0,0 +1,193 @@
1
+ import { betaTool } from "@anthropic-ai/sdk/helpers/beta/json-schema";
2
+ import { artifact } from "../artifacts.js";
3
+ import { AgentJamError } from "../errors.js";
4
+ import { currentTask } from "../tasks/incoming.js";
5
+ import { constructAdapterScreen, constructModelContent, constructTaskContent, executeTool, getNetworkTools, toHistory, } from "./shared.js";
6
+ const toContentBlock = (part) => {
7
+ switch (part.type) {
8
+ case "text":
9
+ return part;
10
+ case "image":
11
+ return {
12
+ type: "image",
13
+ source: { type: "base64", media_type: part.mimeType, data: part.data },
14
+ };
15
+ case "document":
16
+ return {
17
+ type: "document",
18
+ title: part.name,
19
+ source: { type: "base64", media_type: part.mimeType, data: part.data },
20
+ };
21
+ default: {
22
+ const unknown = part;
23
+ throw new AgentJamError(`Unknown content part: ${String(unknown)}`);
24
+ }
25
+ }
26
+ };
27
+ const toContent = ({ text, files }) => [
28
+ { type: "text", text },
29
+ ...files.map(toContentBlock),
30
+ ];
31
+ /**
32
+ * Exposes the agent's network tools to a hand-written `messages.create()` loop.
33
+ *
34
+ * @param agent The connected agent whose network tools to expose.
35
+ * @param pick The network tools to expose. Defaults to every tool `connect()` enabled.
36
+ * @returns The tool definitions to send, and a dispatcher for the model's calls.
37
+ * @throws {AgentJamError} If `pick` names a tool `connect()` didn't enable.
38
+ */
39
+ export const anthropicTools = (agent, pick) => {
40
+ const picked = getNetworkTools(agent, pick);
41
+ const tools = new Map(picked.map((tool) => [tool.name, tool]));
42
+ return {
43
+ definitions: picked.map(({ name, description, inputSchema }) => ({
44
+ name,
45
+ description,
46
+ input_schema: inputSchema,
47
+ })),
48
+ execute: async (toolUse, options) => {
49
+ const tool = tools.get(toolUse.name);
50
+ if (!tool)
51
+ return undefined;
52
+ const output = await executeTool(tool, toolUse.input, options);
53
+ return {
54
+ type: "tool_result",
55
+ tool_use_id: toolUse.id,
56
+ content: toContent(output),
57
+ };
58
+ },
59
+ };
60
+ };
61
+ /**
62
+ * Converts the agent's network tools into runnable tools for Anthropic's beta tool runner.
63
+ *
64
+ * @param agent The connected agent whose network tools to convert.
65
+ * @param pick The network tools to convert. Defaults to every tool `connect()` enabled.
66
+ * @returns The network tools, to add next to your own.
67
+ * @throws {AgentJamError} If `pick` names a tool `connect()` didn't enable.
68
+ */
69
+ export const anthropicRunnableTools = (agent, pick) => getNetworkTools(agent, pick).map((tool) => betaTool({
70
+ name: tool.name,
71
+ description: tool.description,
72
+ inputSchema: tool.inputSchema,
73
+ run: async (input, context) => {
74
+ const output = await executeTool(tool, input, {
75
+ signal: context?.signal ?? undefined,
76
+ });
77
+ return toContent(output);
78
+ },
79
+ }));
80
+ const toUserMessage = (content) => ({
81
+ role: "user",
82
+ content: toContent(content),
83
+ });
84
+ /**
85
+ * Maps a message and the earlier turns of its conversation to Anthropic message params. The message's own
86
+ * files become image, document and text blocks, while earlier turns are text only.
87
+ *
88
+ * @param message A message received by `onMessage`.
89
+ * @returns The conversation, oldest turn first.
90
+ */
91
+ export const toAnthropicMessages = async (message) => [
92
+ ...toHistory(message).map(({ role, text }) => ({ role, content: text })),
93
+ toUserMessage(await constructModelContent(message)),
94
+ ];
95
+ const textOf = (message) => message.content
96
+ .flatMap((block) => (block.type === "text" ? [block.text] : []))
97
+ .join("");
98
+ const toBlocks = (message) => {
99
+ const content = message?.content ?? [];
100
+ return typeof content === "string"
101
+ ? [{ type: "text", text: content }]
102
+ : content;
103
+ };
104
+ /** Adds the messages queued in a task's inbox once a turn ends, after the results of the turn's tool calls. */
105
+ const steerRunner = async (runner, turn, inbox) => {
106
+ const messages = inbox.take();
107
+ if (messages.length === 0)
108
+ return;
109
+ const reply = await turn.finalMessage();
110
+ const results = await runner.generateToolResponse();
111
+ const steering = await Promise.all(messages.map(async (message) => toContent(await constructModelContent(message))));
112
+ // WARNING: messages pushed between turns replace the turn's reply, so the reply and its tool results go first.
113
+ runner.pushMessages({ role: "assistant", content: reply.content }, { role: "user", content: [...toBlocks(results), ...steering.flat()] });
114
+ };
115
+ async function* answerText(runner, inbox) {
116
+ for await (const turn of runner) {
117
+ for await (const event of turn) {
118
+ if (event.type === "content_block_delta" &&
119
+ event.delta.type === "text_delta") {
120
+ yield event.delta.text;
121
+ }
122
+ else if (event.type === "content_block_start" &&
123
+ event.content_block.type === "tool_use") {
124
+ await currentTask()?.update(`Calling ${event.content_block.name}`);
125
+ }
126
+ }
127
+ await steerRunner(runner, turn, inbox);
128
+ }
129
+ }
130
+ const fitTool = "record_fit";
131
+ const screenTokens = 1024;
132
+ const textOfSystem = (system) => typeof system === "string"
133
+ ? system
134
+ : system?.map(({ text }) => text).join("\n\n");
135
+ const constructJudge = (client) => (model) => async ({ system, prompt, schema }, signal) => {
136
+ const reply = await client.messages.create({
137
+ model,
138
+ max_tokens: screenTokens,
139
+ system,
140
+ messages: [{ role: "user", content: prompt }],
141
+ tools: [
142
+ {
143
+ name: fitTool,
144
+ description: "Records how fully the agent can do the proposal",
145
+ input_schema: schema,
146
+ },
147
+ ],
148
+ tool_choice: { type: "tool", name: fitTool },
149
+ }, { signal });
150
+ const recorded = reply.content.find((block) => block.type === "tool_use");
151
+ if (!recorded)
152
+ throw new AgentJamError("The model recorded no fit");
153
+ return JSON.stringify(recorded.input);
154
+ };
155
+ /**
156
+ * Runs incoming messages and tasks through Anthropic's tool runner with `params`, adding the
157
+ * network tools to its own. Task output streams back as a text artifact.
158
+ *
159
+ * @param client The Anthropic client to run the model with.
160
+ * @param params The tool runner params, including your own tools.
161
+ * @param options Whether to screen proposals with the agent's model before accepting them.
162
+ * @returns Handlers to spread into `connect()`.
163
+ */
164
+ export const fromAnthropic = (client, params, { screen } = {}) => {
165
+ const tools = params.tools ?? [];
166
+ const settings = (agent, messages) => ({
167
+ ...params,
168
+ messages,
169
+ tools: [...tools, ...anthropicRunnableTools(agent)],
170
+ });
171
+ return {
172
+ toolNames: tools.flatMap((tool) => ("name" in tool ? [tool.name] : [])),
173
+ ...constructAdapterScreen(screen, {
174
+ model: params.model,
175
+ instructions: textOfSystem(params.system),
176
+ judgeWith: constructJudge(client),
177
+ }),
178
+ onMessage: async (message, agent) => {
179
+ const runner = client.beta.messages.toolRunner(settings(agent, await toAnthropicMessages(message)));
180
+ return textOf(await runner);
181
+ },
182
+ onTask: async (task, agent) => {
183
+ const inbox = task.openInbox();
184
+ const content = await constructTaskContent(task);
185
+ const runner = client.beta.messages.toolRunner({
186
+ ...settings(agent, [toUserMessage(content)]),
187
+ stream: true,
188
+ }, { signal: task.signal });
189
+ return artifact(answerText(runner, inbox));
190
+ },
191
+ };
192
+ };
193
+ //# sourceMappingURL=anthropic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/adapters/anthropic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,4CAA4C,CAAC;AAmBtE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAInD,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,WAAW,EACX,eAAe,EACf,SAAS,GACV,MAAM,aAAa,CAAC;AAiCrB,MAAM,cAAc,GAAG,CAAC,IAAiB,EAAgB,EAAE;IACzD,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB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,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC5C,MAAM,EAAE,IAAI;aACb,EACD,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CACxB,CAAC;YAEF,OAAO,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { EasyInputMessage, FunctionTool, ResponseFunctionToolCall, ResponseInputItem } from "openai/resources/responses/responses";
2
+ import type { Agent } from "../agent.js";
3
+ import type { ToolCallOptions, ToolName } from "../tools.js";
4
+ import type { IncomingMessage } from "../types.js";
5
+ /** The network tools as Responses API function definitions, plus a dispatcher for the model's calls to them. */
6
+ export type OpenAITools = {
7
+ /** The function definitions to send alongside your own. */
8
+ definitions: FunctionTool[];
9
+ /**
10
+ * Runs a call to a network tool.
11
+ *
12
+ * @param call The model's function call output item.
13
+ * @param options Forwarded to the tool, e.g. an abort signal.
14
+ * @returns The tool's output item, or `undefined` if the call is for one of your tools.
15
+ */
16
+ execute: (call: ResponseFunctionToolCall, options?: ToolCallOptions) => Promise<ResponseInputItem.FunctionCallOutput | undefined>;
17
+ };
18
+ /**
19
+ * Exposes the agent's network tools to a hand-written Responses API loop.
20
+ *
21
+ * @param agent The connected agent whose network tools to expose.
22
+ * @param pick The network tools to expose. Defaults to every tool `connect()` enabled.
23
+ * @returns The function definitions to send, and a dispatcher for the model's calls.
24
+ * @throws {AgentJamError} If `pick` names a tool `connect()` didn't enable.
25
+ */
26
+ export declare const openaiTools: (agent: Agent, pick?: ToolName[]) => OpenAITools;
27
+ /**
28
+ * Maps a message and the earlier turns of its conversation to Responses API input messages. The message's
29
+ * own files become image, file and text content, while earlier turns are text only.
30
+ *
31
+ * @param message A message received by `onMessage`.
32
+ * @returns The conversation, oldest turn first.
33
+ */
34
+ export declare const toResponsesInput: (message: IncomingMessage) => Promise<EasyInputMessage[]>;
35
+ //# sourceMappingURL=openai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/adapters/openai.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAUnD,gHAAgH;AAChH,MAAM,MAAM,WAAW,GAAG;IACxB,2DAA2D;IAC3D,WAAW,EAAE,YAAY,EAAE,CAAC;IAC5B;;;;;;OAMG;IACH,OAAO,EAAE,CACP,IAAI,EAAE,wBAAwB,EAC9B,OAAO,CAAC,EAAE,eAAe,KACtB,OAAO,CAAC,iBAAiB,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAAC;CAChE,CAAC;AA+CF;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,UAAW,KAAK,SAAS,QAAQ,EAAE,KAAG,WA6B7D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,YAClB,eAAe,KACvB,OAAO,CAAC,gBAAgB,EAAE,CAG5B,CAAC"}
@@ -0,0 +1,80 @@
1
+ import { AgentJamError } from "../errors.js";
2
+ import { constructModelContent, executeTool, getNetworkTools, toDataUrl, toHistory, } from "./shared.js";
3
+ const toInputContent = (part) => {
4
+ switch (part.type) {
5
+ case "text":
6
+ return { type: "input_text", text: part.text };
7
+ case "image":
8
+ return {
9
+ type: "input_image",
10
+ detail: "auto",
11
+ image_url: toDataUrl(part),
12
+ };
13
+ case "document":
14
+ return {
15
+ type: "input_file",
16
+ filename: part.name,
17
+ file_data: toDataUrl(part),
18
+ };
19
+ default: {
20
+ const unknown = part;
21
+ throw new AgentJamError(`Unknown content part: ${String(unknown)}`);
22
+ }
23
+ }
24
+ };
25
+ const toContent = ({ text, files }) => [
26
+ { type: "input_text", text },
27
+ ...files.map(toInputContent),
28
+ ];
29
+ const parseArguments = (text) => {
30
+ try {
31
+ return JSON.parse(text);
32
+ }
33
+ catch {
34
+ return undefined;
35
+ }
36
+ };
37
+ /**
38
+ * Exposes the agent's network tools to a hand-written Responses API loop.
39
+ *
40
+ * @param agent The connected agent whose network tools to expose.
41
+ * @param pick The network tools to expose. Defaults to every tool `connect()` enabled.
42
+ * @returns The function definitions to send, and a dispatcher for the model's calls.
43
+ * @throws {AgentJamError} If `pick` names a tool `connect()` didn't enable.
44
+ */
45
+ export const openaiTools = (agent, pick) => {
46
+ const picked = getNetworkTools(agent, pick);
47
+ const tools = new Map(picked.map((tool) => [tool.name, tool]));
48
+ return {
49
+ definitions: picked.map(({ name, description, inputSchema }) => ({
50
+ type: "function",
51
+ name,
52
+ description,
53
+ parameters: inputSchema,
54
+ strict: true,
55
+ })),
56
+ execute: async (call, options) => {
57
+ const tool = tools.get(call.name);
58
+ if (!tool)
59
+ return undefined;
60
+ const output = await executeTool(tool, parseArguments(call.arguments), options);
61
+ return {
62
+ type: "function_call_output",
63
+ call_id: call.call_id,
64
+ output: toContent(output),
65
+ };
66
+ },
67
+ };
68
+ };
69
+ /**
70
+ * Maps a message and the earlier turns of its conversation to Responses API input messages. The message's
71
+ * own files become image, file and text content, while earlier turns are text only.
72
+ *
73
+ * @param message A message received by `onMessage`.
74
+ * @returns The conversation, oldest turn first.
75
+ */
76
+ export const toResponsesInput = async (message) => [
77
+ ...toHistory(message).map(({ role, text }) => ({ role, content: text })),
78
+ { role: "user", content: toContent(await constructModelContent(message)) },
79
+ ];
80
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/adapters/openai.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C,OAAO,EACL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,EAAE,SAAS,CAAC,MAAM,qBAAqB,CAAC,OAAO,CAAC,CAAC,EAAE;CAC3E,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { AgentInputItem, AgentOutputType, Tool } from "@openai/agents";
2
+ import { Agent as OpenAIAgent } from "@openai/agents";
3
+ import type { AdapterHandlers, Agent } from "../agent.js";
4
+ import type { ToolName } from "../tools.js";
5
+ import type { IncomingMessage } from "../types.js";
6
+ import type { AdapterScreen } from "./shared.js";
7
+ /**
8
+ * Converts the agent's network tools into OpenAI Agents SDK function tools.
9
+ *
10
+ * @param agent The connected agent whose network tools to convert.
11
+ * @param pick The network tools to convert. Defaults to every tool `connect()` enabled.
12
+ * @returns The network tools, to add next to your own.
13
+ * @throws {AgentJamError} If `pick` names a tool `connect()` didn't enable.
14
+ */
15
+ export declare const openaiAgentsTools: <TContext>(agent: Agent, pick?: ToolName[]) => Tool<TContext>[];
16
+ /**
17
+ * Maps a message and the earlier turns of its conversation to OpenAI Agents SDK input items. The message's
18
+ * own files become image, file and text items, while earlier turns are text only.
19
+ *
20
+ * @param message A message received by `onMessage`.
21
+ * @returns The conversation, oldest turn first.
22
+ */
23
+ export declare const toAgentInput: (message: IncomingMessage) => Promise<AgentInputItem[]>;
24
+ /** Options for `fromOpenAIAgents()`. */
25
+ export type OpenAIAgentsOptions = {
26
+ /** Screens each proposal with the agent's model, or a cheaper `model`, before accepting it. Defaults to off. */
27
+ screen?: AdapterScreen<OpenAIAgent["model"]>;
28
+ };
29
+ /**
30
+ * Runs incoming messages and tasks through a clone of `base` that also has the network tools.
31
+ * Task output streams back as a text artifact. A run can't take input midway, so tasks open no inbox
32
+ * and the requester's messages about them go to `onMessage`.
33
+ *
34
+ * @param base The OpenAI agent to run, including your own tools.
35
+ * @param options Whether to screen proposals with the agent's model before accepting them.
36
+ * @returns Handlers to spread into `connect()`.
37
+ */
38
+ export declare const fromOpenAIAgents: <TContext, TOutput extends AgentOutputType>(base: OpenAIAgent<TContext, TOutput>, { screen }?: OpenAIAgentsOptions) => AdapterHandlers;
39
+ //# sourceMappingURL=openaiAgents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openaiAgents.d.ts","sourceRoot":"","sources":["../../src/adapters/openaiAgents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EAGf,IAAI,EAEL,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,KAAK,IAAI,WAAW,EAIrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAK1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAA6B,MAAM,aAAa,CAAC;AAW5E;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,SACjC,KAAK,SACL,QAAQ,EAAE,KAChB,IAAI,CAAC,QAAQ,CAAC,EAYd,CAAC;AAwDJ;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,YACd,eAAe,KACvB,OAAO,CAAC,cAAc,EAAE,CAK1B,CAAC;AAyCF,wCAAwC;AACxC,MAAM,MAAM,mBAAmB,GAAG;IAChC,gHAAgH;IAChH,MAAM,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;CAC9C,CAAC;AAoBF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,EAAE,OAAO,SAAS,eAAe,QAClE,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,eACxB,mBAAmB,KAC9B,eAiCF,CAAC"}
@@ -0,0 +1,152 @@
1
+ import { assistant, Agent as OpenAIAgent, run, tool, user, } from "@openai/agents";
2
+ import { artifact } from "../artifacts.js";
3
+ import { AgentJamError } from "../errors.js";
4
+ import { currentTask } from "../tasks/incoming.js";
5
+ import { constructAdapterScreen, constructModelContent, constructTaskContent, executeTool, getNetworkTools, toDataUrl, toHistory, } from "./shared.js";
6
+ /**
7
+ * Converts the agent's network tools into OpenAI Agents SDK function tools.
8
+ *
9
+ * @param agent The connected agent whose network tools to convert.
10
+ * @param pick The network tools to convert. Defaults to every tool `connect()` enabled.
11
+ * @returns The network tools, to add next to your own.
12
+ * @throws {AgentJamError} If `pick` names a tool `connect()` didn't enable.
13
+ */
14
+ export const openaiAgentsTools = (agent, pick) => getNetworkTools(agent, pick).map((network) => tool({
15
+ name: network.name,
16
+ description: network.description,
17
+ parameters: network.inputSchema,
18
+ strict: true,
19
+ execute: async (input, _context, details) => toToolOutput(await executeTool(network, input, { signal: details?.signal })),
20
+ }));
21
+ const toInputContent = (part) => {
22
+ switch (part.type) {
23
+ case "text":
24
+ return { type: "input_text", text: part.text };
25
+ case "image":
26
+ return { type: "input_image", image: toDataUrl(part) };
27
+ case "document":
28
+ return { type: "input_file", file: toDataUrl(part), filename: part.name };
29
+ default: {
30
+ const unknown = part;
31
+ throw new AgentJamError(`Unknown content part: ${String(unknown)}`);
32
+ }
33
+ }
34
+ };
35
+ const toOutputContent = (part) => {
36
+ switch (part.type) {
37
+ case "text":
38
+ return part;
39
+ case "image":
40
+ return {
41
+ type: "image",
42
+ image: { data: part.data, mediaType: part.mimeType },
43
+ };
44
+ case "document":
45
+ return {
46
+ type: "file",
47
+ file: {
48
+ data: part.data,
49
+ mediaType: part.mimeType,
50
+ filename: part.name,
51
+ },
52
+ };
53
+ default: {
54
+ const unknown = part;
55
+ throw new AgentJamError(`Unknown content part: ${String(unknown)}`);
56
+ }
57
+ }
58
+ };
59
+ const toToolOutput = ({ text, files }) => [
60
+ toOutputContent({ type: "text", text }),
61
+ ...files.map(toOutputContent),
62
+ ];
63
+ const toUserItem = ({ text, files }) => user([{ type: "input_text", text }, ...files.map(toInputContent)]);
64
+ /**
65
+ * Maps a message and the earlier turns of its conversation to OpenAI Agents SDK input items. The message's
66
+ * own files become image, file and text items, while earlier turns are text only.
67
+ *
68
+ * @param message A message received by `onMessage`.
69
+ * @returns The conversation, oldest turn first.
70
+ */
71
+ export const toAgentInput = async (message) => [
72
+ ...toHistory(message).map(({ role, text }) => role === "user" ? user(text) : assistant(text)),
73
+ toUserItem(await constructModelContent(message)),
74
+ ];
75
+ const calledTool = (event) => {
76
+ if (event.type !== "run_item_stream_event")
77
+ return undefined;
78
+ if (event.item.type !== "tool_call_item")
79
+ return undefined;
80
+ const { rawItem } = event.item;
81
+ return "name" in rawItem ? rawItem.name : rawItem.type;
82
+ };
83
+ const assertFinished = (result) => {
84
+ if (result.interruptions.length > 0) {
85
+ throw new AgentJamError("The agent paused for tool approval, which AgentJam doesn't support yet");
86
+ }
87
+ };
88
+ async function* answerText(result) {
89
+ for await (const event of result) {
90
+ const toolName = calledTool(event);
91
+ if (event.type === "raw_model_stream_event" &&
92
+ event.data.type === "output_text_delta") {
93
+ yield event.data.delta;
94
+ }
95
+ else if (toolName !== undefined) {
96
+ await currentTask()?.update(`Calling ${toolName}`);
97
+ }
98
+ }
99
+ await result.completed;
100
+ assertFinished(result);
101
+ }
102
+ const constructJudge = (name) => (model) => async ({ system, prompt, schema }, signal) => {
103
+ const screener = new OpenAIAgent({
104
+ name: `${name} screener`,
105
+ instructions: system,
106
+ model,
107
+ outputType: { type: "json_schema", name: "fit", strict: true, schema },
108
+ });
109
+ const { finalOutput } = await run(screener, prompt, { signal });
110
+ return typeof finalOutput === "string"
111
+ ? finalOutput
112
+ : JSON.stringify(finalOutput);
113
+ };
114
+ /**
115
+ * Runs incoming messages and tasks through a clone of `base` that also has the network tools.
116
+ * Task output streams back as a text artifact. A run can't take input midway, so tasks open no inbox
117
+ * and the requester's messages about them go to `onMessage`.
118
+ *
119
+ * @param base The OpenAI agent to run, including your own tools.
120
+ * @param options Whether to screen proposals with the agent's model before accepting them.
121
+ * @returns Handlers to spread into `connect()`.
122
+ */
123
+ export const fromOpenAIAgents = (base, { screen } = {}) => {
124
+ const build = (agent) => base.clone({
125
+ tools: [...base.tools, ...openaiAgentsTools(agent)],
126
+ });
127
+ return {
128
+ toolNames: base.tools.map((existing) => existing.name),
129
+ ...constructAdapterScreen(screen, {
130
+ model: base.model,
131
+ instructions: typeof base.instructions === "string" ? base.instructions : undefined,
132
+ judgeWith: constructJudge(base.name),
133
+ }),
134
+ onMessage: async (message, agent) => {
135
+ const result = await run(build(agent), await toAgentInput(message));
136
+ assertFinished(result);
137
+ const { finalOutput } = result;
138
+ return typeof finalOutput === "string"
139
+ ? finalOutput
140
+ : JSON.stringify(finalOutput);
141
+ },
142
+ onTask: async (task, agent) => {
143
+ const content = await constructTaskContent(task);
144
+ const result = await run(build(agent), [toUserItem(content)], {
145
+ stream: true,
146
+ signal: task.signal,
147
+ });
148
+ return artifact(answerText(result));
149
+ },
150
+ };
151
+ };
152
+ //# sourceMappingURL=openaiAgents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openaiAgents.js","sourceRoot":"","sources":["../../src/adapters/openaiAgents.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,SAAS,EACT,KAAK,IAAI,WAAW,EACpB,GAAG,EACH,IAAI,EACJ,IAAI,GACL,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAInD,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,WAAW,EACX,eAAe,EACf,SAAS,EACT,SAAS,GACV,MAAM,aAAa,CAAC;AAErB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,KAAY,EACZ,IAAiB,EACC,EAAE,CACpB,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAC3C,IAAI,CAAC;I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AAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;YAClC,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;YACpE,cAAc,CAAC,MAAM,CAAC,CAAC;YAEvB,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;YAC/B,OAAO,OAAO,WAAW,KAAK,QAAQ;gBACpC,CAAC,CAAC,WAAW;gBACb,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAClC,CAAC;QACD,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;YAC5B,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC,IAAI,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE;gBAC5D,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,72 @@
1
+ import type { AdapterHandlers, Agent } from "../agent.js";
2
+ import type { Judge, ScreenSettings } from "../screening.js";
3
+ import type { IncomingTask } from "../tasks/incoming.js";
4
+ import type { NetworkTool, ToolCallOptions, ToolName } from "../tools.js";
5
+ import type { Attachment, IncomingMessage } from "../types.js";
6
+ export declare const maxShownFiles = 20;
7
+ export declare const maxShownBytes: number;
8
+ export declare const maxImageBytes: number;
9
+ export declare const maxDocumentBytes: number;
10
+ export declare const maxTextBytes: number;
11
+ declare const imageTypes: readonly ["image/png", "image/jpeg", "image/gif", "image/webp"];
12
+ type ImageType = (typeof imageTypes)[number];
13
+ /** A provider-neutral piece of what the model sees, which each adapter maps to its SDK's content format. */
14
+ export type ContentPart = {
15
+ type: "text";
16
+ text: string;
17
+ } | {
18
+ type: "image";
19
+ name: string;
20
+ mimeType: ImageType;
21
+ data: string;
22
+ } | {
23
+ type: "document";
24
+ name: string;
25
+ mimeType: "application/pdf";
26
+ data: string;
27
+ };
28
+ /** What the model sees of a task, message or tool result: its text, then the parts its files convert to. */
29
+ export type ModelContent = {
30
+ text: string;
31
+ files: ContentPart[];
32
+ };
33
+ /** A conversation turn from the receiving agent's point of view, where the sender is the user. */
34
+ export type Turn = {
35
+ role: "user" | "assistant";
36
+ text: string;
37
+ };
38
+ /**
39
+ * Converts the files of one model call into content parts, in order. Images and PDFs become image and
40
+ * document parts, text files are inlined, and the rest, or any past the caps, are only described.
41
+ */
42
+ export declare const convertFiles: (files: File[]) => Promise<ContentPart[]>;
43
+ export declare const constructModelContent: (source: {
44
+ text: string;
45
+ attachments: Attachment[];
46
+ }) => Promise<ModelContent>;
47
+ /** Builds what the model sees of a task: its text, structured input and a recap of the task it follows up on. */
48
+ export declare const constructTaskContent: ({ text, input, previous, attachments, }: Pick<IncomingTask, "text" | "input" | "previous" | "attachments">) => Promise<ModelContent>;
49
+ /**
50
+ * Maps the earlier turns of a message's conversation, which keep no files, from the receiver's point of view,
51
+ * after a recap of the task the message is about.
52
+ */
53
+ export declare const toHistory: ({ from, history, task, taskId, steer, }: IncomingMessage) => Turn[];
54
+ export declare const toDataUrl: ({ mimeType, data, }: Exclude<ContentPart, {
55
+ type: "text";
56
+ }>) => string;
57
+ export declare const executeTool: (tool: NetworkTool, input: unknown, options?: ToolCallOptions) => Promise<ModelContent>;
58
+ export declare const getNetworkTools: (agent: Agent, pick?: ToolName[]) => NetworkTool[];
59
+ /** An adapter's `screen` option: `true` to screen proposals with the adapter's own model, or settings that can name a cheaper `model`. */
60
+ export type AdapterScreen<Model> = boolean | (ScreenSettings & {
61
+ /** The model to screen with. Defaults to the adapter's own. */
62
+ model?: Model | undefined;
63
+ });
64
+ type ScreenDefaults<Model> = {
65
+ model: Model;
66
+ instructions: string | undefined;
67
+ judgeWith: (model: Model) => Judge;
68
+ };
69
+ /** Builds the `screen` an adapter spreads into its handlers, adding the adapter's instructions to the screen's own. */
70
+ export declare const constructAdapterScreen: <Model>(option: AdapterScreen<Model> | undefined, { model, instructions, judgeWith }: ScreenDefaults<Model>) => Pick<AdapterHandlers, "screen">;
71
+ export {};
72
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/adapters/shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAI/D,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC,eAAO,MAAM,aAAa,QAAgB,CAAC;AAG3C,eAAO,MAAM,aAAa,QAAkB,CAAC;AAE7C,eAAO,MAAM,gBAAgB,QAAgB,CAAC;AAE9C,eAAO,MAAM,YAAY,QAAa,CAAC;AAEvC,QAAA,MAAM,UAAU,YACd,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,CACJ,CAAC;AAYX,KAAK,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7C,4GAA4G;AAC5G,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE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