@pattern-js/mod-agents 0.2.2 → 0.3.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.
package/dist/loop.js ADDED
@@ -0,0 +1,300 @@
1
+ /**
2
+ * @pattern-js/mod-agents — the native agent run loop.
3
+ *
4
+ * Replaces the @openai/agents Runner: we drive the model↔tool turn loop
5
+ * ourselves over the neutral AiModelService (mod-ai implements it). Each model
6
+ * step is a single `streamTurn` call; THIS loop owns multi-step. Tools are
7
+ * linked sub-runs (`ctx.invoke`) / op-registry calls / MCP; handoffs swap the
8
+ * active agent; guardrails are tool sub-runs; HITL pauses with a stateToken.
9
+ *
10
+ * It emits the neutral `turnEventSchema` and the produced stream ALWAYS
11
+ * terminates with a `done` event — complete | interrupted | error | cancelled.
12
+ */
13
+ import { agentsService } from "./well-known.js";
14
+ import { aiMcpService } from "./model-service.js";
15
+ const encodeState = (s) => JSON.stringify(s);
16
+ const decodeState = (t) => JSON.parse(t);
17
+ const slug = (name) => name.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
18
+ const transferName = (name) => `transfer_to_${slug(name)}`;
19
+ /** Plain text of a message's content (for guardrail payloads). */
20
+ function textOfContent(content) {
21
+ if (typeof content === "string")
22
+ return content;
23
+ return content.map((p) => (p.type === "text" ? p.text : "")).join("");
24
+ }
25
+ function lastUserText(messages) {
26
+ for (let i = messages.length - 1; i >= 0; i--) {
27
+ if (messages[i].role === "user")
28
+ return textOfContent(messages[i].content);
29
+ }
30
+ return "";
31
+ }
32
+ /**
33
+ * Resolve a descriptor's toolset + handoffs into model-facing tools and
34
+ * dispatchers. Workflow tools become linked sub-runs; op tools call the
35
+ * registry; MCP tools resolve through mod-ai's MCP seam. Throws loudly for an
36
+ * unknown op tool (pre-flight, when called from the op's execute).
37
+ */
38
+ async function resolveAgent(descriptor, ctx) {
39
+ const tools = [];
40
+ const dispatch = new Map();
41
+ const handoffs = new Map();
42
+ const svc = agentsService(ctx);
43
+ const addToolset = async (toolset) => {
44
+ for (const ref of toolset?.tools ?? []) {
45
+ if (ref.origin === "workflow") {
46
+ tools.push({
47
+ name: ref.name,
48
+ description: ref.description,
49
+ parameters: ref.params ?? { type: "object", properties: {} },
50
+ needsApproval: ref.needsApproval,
51
+ });
52
+ dispatch.set(ref.name, {
53
+ needsApproval: ref.needsApproval ?? false,
54
+ invoke: async (args) => {
55
+ ctx.trace.addEvent("tool.call", { tool: ref.name, workflowId: ref.workflowId });
56
+ const outputs = await ctx.invoke({ workflowId: ref.workflowId }, { args });
57
+ return outputs.result === undefined ? outputs : outputs.result;
58
+ },
59
+ });
60
+ }
61
+ else if (ref.origin === "op") {
62
+ const reg = svc.getOpTool(ref.name);
63
+ if (!reg) {
64
+ throw new Error(`agents: no registered op tool named "${ref.name}" (mods register them in setup)`);
65
+ }
66
+ tools.push({ name: reg.name, description: reg.description, parameters: reg.params, needsApproval: ref.needsApproval ?? reg.needsApproval });
67
+ dispatch.set(reg.name, {
68
+ needsApproval: (ref.needsApproval ?? reg.needsApproval) ?? false,
69
+ invoke: async (args) => reg.execute(args, ctx),
70
+ });
71
+ }
72
+ else {
73
+ // MCP: discovery + execution live in mod-ai (keeps the MCP client out of
74
+ // this provider-SDK-free package).
75
+ const mcp = aiMcpService(ctx);
76
+ for (const t of await mcp.listTools(ref)) {
77
+ tools.push(t);
78
+ dispatch.set(t.name, {
79
+ needsApproval: t.needsApproval ?? false,
80
+ invoke: async (args) => mcp.callTool(ref, t.name, args),
81
+ });
82
+ }
83
+ }
84
+ }
85
+ };
86
+ await addToolset(descriptor.tools);
87
+ for (const h of descriptor.handoffs ?? []) {
88
+ const name = transferName(h.name);
89
+ handoffs.set(name, h);
90
+ tools.push({
91
+ name,
92
+ description: h.handoffDescription ?? `Hand off the conversation to ${h.name}.`,
93
+ parameters: { type: "object", properties: {} },
94
+ });
95
+ }
96
+ return { descriptor, tools, dispatch, handoffs };
97
+ }
98
+ const guardrailsOf = (d, dir) => (d.guardrails ?? []).filter((g) => g.direction === dir);
99
+ /** Run a guardrail tool workflow; returns whether it tripped. */
100
+ async function runGuardrail(g, text, ctx) {
101
+ const outputs = await ctx.invoke({ workflowId: g.workflowId }, { args: { input: text, direction: g.direction } });
102
+ const result = (outputs.result ?? outputs);
103
+ return Boolean(result.tripwire);
104
+ }
105
+ /**
106
+ * Run an agent turn (fresh or resumed). Returns the neutral event stream plus a
107
+ * settled outcome. Mirrors the old `pumpTurn` contract: the stream never
108
+ * rejects and always closes with `done`.
109
+ */
110
+ export function startTurn(params) {
111
+ const { ctx, model, descriptor, ids, signal, maxTurns } = params;
112
+ let resolveOutcome;
113
+ const outcome = new Promise((r) => (resolveOutcome = r));
114
+ const events = new ReadableStream({
115
+ start: async (controller) => {
116
+ const emit = (ev) => controller.enqueue(ev);
117
+ const settle = (o) => resolveOutcome(o);
118
+ const findAgent = (name) => {
119
+ const walk = (a) => {
120
+ if (a.name === name)
121
+ return a;
122
+ for (const h of a.handoffs ?? []) {
123
+ const hit = walk(h);
124
+ if (hit)
125
+ return hit;
126
+ }
127
+ return undefined;
128
+ };
129
+ return walk(descriptor) ?? descriptor;
130
+ };
131
+ try {
132
+ const messages = [...params.messages];
133
+ let active = await resolveAgent(params.resume ? findAgent(params.resume.saved.activeAgent) : descriptor, ctx);
134
+ // ── resume: apply the human's decisions to the pending approvals ──
135
+ if (params.resume) {
136
+ for (const d of params.resume.decisions) {
137
+ const p = params.resume.saved.pending.find((x) => x.callId === d.id);
138
+ if (!p)
139
+ throw new Error(`agents.run.resume: no pending approval with id "${d.id}"`);
140
+ if (d.approved) {
141
+ const disp = active.dispatch.get(p.toolName);
142
+ emit({ ...ids, type: "tool.activity", toolName: p.toolName, callId: p.callId, phase: "start", args: p.args });
143
+ try {
144
+ const result = disp ? await disp.invoke(p.args) : undefined;
145
+ emit({ ...ids, type: "tool.activity", toolName: p.toolName, callId: p.callId, phase: "done", result });
146
+ messages.push({ role: "tool", toolCallId: p.callId, toolName: p.toolName, content: stringifyResult(result) });
147
+ }
148
+ catch (err) {
149
+ emit({ ...ids, type: "tool.activity", toolName: p.toolName, callId: p.callId, phase: "error", error: errMessage(err) });
150
+ messages.push({ role: "tool", toolCallId: p.callId, toolName: p.toolName, content: `error: ${errMessage(err)}` });
151
+ }
152
+ }
153
+ else {
154
+ messages.push({ role: "tool", toolCallId: p.callId, toolName: p.toolName, content: "The user declined this tool call." });
155
+ }
156
+ }
157
+ }
158
+ else {
159
+ // ── input guardrails (fresh runs only) ──
160
+ for (const g of guardrailsOf(active.descriptor, "input")) {
161
+ if (await runGuardrail(g, lastUserText(messages), ctx)) {
162
+ emit({ ...ids, type: "error", message: `input guardrail "${g.name}" tripped`, code: "guardrail.input" });
163
+ emit({ ...ids, type: "done", stopReason: "error" });
164
+ return settle({ stopReason: "error", output: null, history: null, stateToken: null });
165
+ }
166
+ }
167
+ }
168
+ // ── the turn loop ──
169
+ for (let turn = 0;; turn++) {
170
+ if (turn >= maxTurns) {
171
+ emit({ ...ids, type: "error", message: `max turns (${maxTurns}) exceeded`, code: "max_turns" });
172
+ emit({ ...ids, type: "done", stopReason: "error" });
173
+ return settle({ stopReason: "error", output: null, history: null, stateToken: null });
174
+ }
175
+ let text = "";
176
+ const toolCalls = [];
177
+ for await (const chunk of model.streamTurn({
178
+ ctx,
179
+ modelRef: active.descriptor.model,
180
+ system: active.descriptor.instructions,
181
+ // A snapshot: the loop mutates `messages` after the step settles.
182
+ messages: [...messages],
183
+ tools: active.tools,
184
+ outputSchema: active.descriptor.outputSchema,
185
+ signal,
186
+ })) {
187
+ if (chunk.type === "text-delta") {
188
+ text += chunk.delta;
189
+ emit({ ...ids, type: "text.delta", delta: chunk.delta });
190
+ }
191
+ else if (chunk.type === "tool-call" || chunk.type === "tool-approval-request") {
192
+ toolCalls.push({ callId: chunk.callId, toolName: chunk.toolName, args: (chunk.args ?? {}) });
193
+ }
194
+ // `finish` and `tool-input-delta` carry no extra events here.
195
+ }
196
+ if (signal.aborted) {
197
+ emit({ ...ids, type: "done", stopReason: "cancelled" });
198
+ return settle({ stopReason: "cancelled", output: null, history: null, stateToken: null });
199
+ }
200
+ // Record the assistant step.
201
+ messages.push({
202
+ role: "assistant",
203
+ content: text,
204
+ toolCalls: toolCalls.length ? toolCalls.map((t) => ({ callId: t.callId, toolName: t.toolName, args: t.args })) : undefined,
205
+ });
206
+ if (text)
207
+ emit({ ...ids, type: "text.done", text });
208
+ // No tool calls → final answer.
209
+ if (toolCalls.length === 0) {
210
+ for (const g of guardrailsOf(active.descriptor, "output")) {
211
+ if (await runGuardrail(g, text, ctx)) {
212
+ emit({ ...ids, type: "error", message: `output guardrail "${g.name}" tripped`, code: "guardrail.output" });
213
+ emit({ ...ids, type: "done", stopReason: "error" });
214
+ return settle({ stopReason: "error", output: null, history: null, stateToken: null });
215
+ }
216
+ }
217
+ const output = active.descriptor.outputSchema ? tryParse(text) : text;
218
+ emit({ ...ids, type: "done", stopReason: "complete" });
219
+ return settle({ stopReason: "complete", output, history: messages, stateToken: null });
220
+ }
221
+ // A handoff outranks everything else this step.
222
+ const handoff = toolCalls.find((t) => active.handoffs.has(t.toolName));
223
+ if (handoff) {
224
+ emit({ ...ids, type: "tool.activity", toolName: "handoff", callId: handoff.callId, phase: "start", args: { to: active.handoffs.get(handoff.toolName).name } });
225
+ active = await resolveAgent(active.handoffs.get(handoff.toolName), ctx);
226
+ emit({ ...ids, type: "tool.activity", toolName: "handoff", callId: handoff.callId, phase: "done" });
227
+ continue;
228
+ }
229
+ // Split into pending-approval vs dispatch-now.
230
+ const pending = [];
231
+ for (const tc of toolCalls) {
232
+ const disp = active.dispatch.get(tc.toolName);
233
+ if (disp?.needsApproval) {
234
+ pending.push(tc);
235
+ continue;
236
+ }
237
+ emit({ ...ids, type: "tool.activity", toolName: tc.toolName, callId: tc.callId, phase: "start", args: tc.args });
238
+ try {
239
+ const result = disp ? await disp.invoke(tc.args) : `error: unknown tool "${tc.toolName}"`;
240
+ emit({ ...ids, type: "tool.activity", toolName: tc.toolName, callId: tc.callId, phase: "done", result });
241
+ messages.push({ role: "tool", toolCallId: tc.callId, toolName: tc.toolName, content: stringifyResult(result) });
242
+ }
243
+ catch (err) {
244
+ emit({ ...ids, type: "tool.activity", toolName: tc.toolName, callId: tc.callId, phase: "error", error: errMessage(err) });
245
+ messages.push({ role: "tool", toolCallId: tc.callId, toolName: tc.toolName, content: `error: ${errMessage(err)}` });
246
+ }
247
+ }
248
+ // Anything awaiting approval pauses the turn (HITL).
249
+ if (pending.length) {
250
+ const stateToken = encodeState({ messages, activeAgent: active.descriptor.name, pending });
251
+ for (const p of pending) {
252
+ emit({ ...ids, type: "approval.request", interruption: { id: p.callId, toolName: p.toolName, args: p.args }, stateToken });
253
+ }
254
+ emit({ ...ids, type: "done", stopReason: "interrupted" });
255
+ return settle({ stopReason: "interrupted", output: null, history: messages, stateToken });
256
+ }
257
+ // else: dispatched tools → loop for the next model step.
258
+ }
259
+ }
260
+ catch (err) {
261
+ if (signal.aborted) {
262
+ emit({ ...ids, type: "done", stopReason: "cancelled" });
263
+ settle({ stopReason: "cancelled", output: null, history: null, stateToken: null });
264
+ }
265
+ else {
266
+ emit({ ...ids, type: "error", message: errMessage(err), code: errorCode(err) });
267
+ emit({ ...ids, type: "done", stopReason: "error" });
268
+ settle({ stopReason: "error", output: null, history: null, stateToken: null });
269
+ }
270
+ }
271
+ finally {
272
+ controller.close();
273
+ }
274
+ },
275
+ });
276
+ return { events, outcome };
277
+ }
278
+ /** Re-expose the saved state shape for the resume op. */
279
+ export { decodeState };
280
+ function stringifyResult(result) {
281
+ return typeof result === "string" ? result : JSON.stringify(result ?? null);
282
+ }
283
+ function errMessage(err) {
284
+ return err instanceof Error ? err.message : String(err);
285
+ }
286
+ function errorCode(err) {
287
+ const name = err?.name ?? "";
288
+ if (/Abort/.test(name))
289
+ return undefined;
290
+ return undefined;
291
+ }
292
+ function tryParse(text) {
293
+ try {
294
+ return JSON.parse(text);
295
+ }
296
+ catch {
297
+ return text;
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AAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
package/dist/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAA0B,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAiB3E,wBAAgB,SAAS,IAAI,UAAU,CAUtC;AAED,yEAAyE;;AACzE,wBAA2B"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAA0B,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAkB3E,wBAAgB,SAAS,IAAI,UAAU,CAUtC;AAED,yEAAyE;;AACzE,wBAA2B"}
package/dist/mod.js CHANGED
@@ -8,6 +8,7 @@ import { localFs, provideFilesystem } from "@pattern-js/runtime-node";
8
8
  import { defineMod } from "@pattern-js/core";
9
9
  import { agentBoundaryOps } from "./boundaries.js";
10
10
  import { agentsOps } from "./ops.js";
11
+ import { agentRunOps } from "./agent-ops.js";
11
12
  import { AgentsRegistry } from "./service.js";
12
13
  import { AGENTS_SERVICE } from "./well-known.js";
13
14
  /** The packaged docs/ chapter (the `docs` contribution points at "agents-docs"). */
@@ -25,7 +26,7 @@ export function agentsMod() {
25
26
  return defineMod({
26
27
  name: "@pattern-js/mod-agents",
27
28
  docs: { filesystem: "agents-docs", title: "Agents", order: 50 },
28
- ops: [...agentBoundaryOps, ...agentsOps],
29
+ ops: [...agentBoundaryOps, ...agentsOps, ...agentRunOps],
29
30
  setup: (engine) => {
30
31
  packagedDocs(engine);
31
32
  engine.provideService(AGENTS_SERVICE, new AgentsRegistry(engine));
package/dist/mod.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAA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CAAC,MAAM,CAAC,CAAC;YACrB,MAAM,CAAC,cAAc,CAAC,cAAc,EAAE,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;QACpE,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,yEAAyE;AACzE,eAAe,SAAS,EAAE,CAAC"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @pattern-js/mod-agents — the neutral model-service seam.
3
+ *
4
+ * The orchestration layer (this mod: the agent loop, compaction) calls a model
5
+ * through THIS interface and nothing else. The capability layer (mod-ai) is the
6
+ * only package that imports the Vercel AI SDK and provides the implementation in
7
+ * its `setup` via `engine.provideService(AI_MODEL_SERVICE, …)`. Only plain JSON
8
+ * and ReadableStreams cross this boundary — no provider SDK types — so mod-agents
9
+ * never depends on mod-ai or any `@ai-sdk/*` package. This generalizes the old
10
+ * `MODEL_PROVIDER_SERVICE` override seam into a provider-neutral one.
11
+ */
12
+ import type { OpContext } from "@pattern-js/core";
13
+ import type { ModelRef, NeutralMessage, ToolRef, Usage } from "./types.js";
14
+ /** The MCP variant of a tool reference (transport + connection details). */
15
+ export type McpToolRef = Extract<ToolRef, {
16
+ origin: "mcp";
17
+ }>;
18
+ /** A tool offered to the model for a turn (JSON-Schema parameters; engine-validated at the boundary.tool). */
19
+ export interface NeutralToolDef {
20
+ name: string;
21
+ description?: string;
22
+ /** JSON Schema for the arguments. */
23
+ parameters: Record<string, unknown>;
24
+ /** Pause for human approval before the loop dispatches this call (HITL). */
25
+ needsApproval?: boolean;
26
+ }
27
+ /**
28
+ * One streamed unit from a SINGLE model step. The loop owns multi-step: it asks
29
+ * for one step, dispatches any tool calls itself (linked sub-runs / handoffs /
30
+ * HITL), then asks again. `finish` always closes a step and carries the complete
31
+ * assistant message to append to history.
32
+ */
33
+ export type NeutralChunk = {
34
+ type: "text-delta";
35
+ delta: string;
36
+ } | {
37
+ type: "tool-call";
38
+ callId: string;
39
+ toolName: string;
40
+ args: unknown;
41
+ } | {
42
+ type: "tool-input-delta";
43
+ callId: string;
44
+ delta: string;
45
+ } | {
46
+ type: "tool-approval-request";
47
+ callId: string;
48
+ toolName: string;
49
+ args: unknown;
50
+ } | {
51
+ type: "finish";
52
+ finishReason: string;
53
+ usage?: Usage;
54
+ message: NeutralMessage;
55
+ };
56
+ export interface StreamTurnInput {
57
+ /** The calling op's context — mod-ai resolves credentials (vault/env) through it. */
58
+ ctx: OpContext;
59
+ /** Which model to call; mod-ai resolves it (undefined = the configured default). */
60
+ modelRef?: ModelRef;
61
+ /** The agent's instructions (system prompt). */
62
+ system?: string;
63
+ /** Full conversation so far, in neutral parts-based shape. */
64
+ messages: NeutralMessage[];
65
+ /** Tools the model may call this step (omitted-execute on the SDK side: the loop dispatches). */
66
+ tools?: NeutralToolDef[];
67
+ /** Resume path: approvals to apply for tools that paused for HITL. */
68
+ toolApprovals?: Array<{
69
+ callId: string;
70
+ approved: boolean;
71
+ }>;
72
+ /** JSON Schema for a structured final answer (provider-enforced when supported). */
73
+ outputSchema?: Record<string, unknown>;
74
+ /** Cooperative cancellation for the in-flight model call. */
75
+ signal: AbortSignal;
76
+ /** Extra provider options merged over the ModelRef's own. */
77
+ providerOptions?: Record<string, unknown>;
78
+ }
79
+ export interface GenerateTextInput {
80
+ ctx: OpContext;
81
+ modelRef?: ModelRef;
82
+ system?: string;
83
+ messages: NeutralMessage[];
84
+ signal: AbortSignal;
85
+ }
86
+ export interface AiModelService {
87
+ /** Stream ONE model step. The loop consumes chunks and drives the next step itself. */
88
+ streamTurn(input: StreamTurnInput): AsyncIterable<NeutralChunk>;
89
+ /** A one-shot, tool-less generation — used by history compaction. */
90
+ generateText(input: GenerateTextInput): Promise<{
91
+ text: string;
92
+ usage?: Usage;
93
+ }>;
94
+ }
95
+ export declare const AI_MODEL_SERVICE = "aiModelService";
96
+ /** Resolve the model service, with a friendly error pointing at mod-ai. */
97
+ export declare function aiModelService(ctx: OpContext): AiModelService;
98
+ /**
99
+ * The MCP seam. The MCP client (connection + tool discovery + calls) lives in
100
+ * mod-ai so this package never imports an MCP SDK. The agent loop resolves an
101
+ * `mcp` tool ref through this when present; absent, MCP tools fail with a hint.
102
+ */
103
+ export interface AiMcpService {
104
+ /** The tools an MCP server exposes (discovered over a pooled connection). */
105
+ listTools(ref: McpToolRef): Promise<NeutralToolDef[]>;
106
+ /** Invoke one tool on the server. */
107
+ callTool(ref: McpToolRef, name: string, args: Record<string, unknown>): Promise<unknown>;
108
+ }
109
+ export declare const AI_MCP_SERVICE = "aiMcpService";
110
+ export declare function aiMcpService(ctx: OpContext): AiMcpService;
111
+ //# sourceMappingURL=model-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-service.d.ts","sourceRoot":"","sources":["../src/model-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAE3E,4EAA4E;AAC5E,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,KAAK,CAAA;CAAE,CAAC,CAAC;AAE7D,8GAA8G;AAC9G,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qCAAqC;IACrC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,4EAA4E;IAC5E,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;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AAM,WAAW,cAAc;IAC7B,uFAAuF;IACvF,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;IAChE,qEAAqE;IACrE,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC;CAClF;AAED,eAAO,MAAM,gBAAgB,mBAAmB,CAAC;AAEjD,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,cAAc,CAS7D;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,6EAA6E;IAC7E,SAAS,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IACtD,qCAAqC;IACrC,QAAQ,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1F;AAED,eAAO,MAAM,cAAc,iBAAiB,CAAC;AAE7C,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,GAAG,YAAY,CAQzD"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @pattern-js/mod-agents — the neutral model-service seam.
3
+ *
4
+ * The orchestration layer (this mod: the agent loop, compaction) calls a model
5
+ * through THIS interface and nothing else. The capability layer (mod-ai) is the
6
+ * only package that imports the Vercel AI SDK and provides the implementation in
7
+ * its `setup` via `engine.provideService(AI_MODEL_SERVICE, …)`. Only plain JSON
8
+ * and ReadableStreams cross this boundary — no provider SDK types — so mod-agents
9
+ * never depends on mod-ai or any `@ai-sdk/*` package. This generalizes the old
10
+ * `MODEL_PROVIDER_SERVICE` override seam into a provider-neutral one.
11
+ */
12
+ export const AI_MODEL_SERVICE = "aiModelService";
13
+ /** Resolve the model service, with a friendly error pointing at mod-ai. */
14
+ export function aiModelService(ctx) {
15
+ const svc = ctx.services[AI_MODEL_SERVICE];
16
+ if (!svc) {
17
+ throw new Error('agents need a model provider — add "@pattern-js/mod-ai" to your pattern.config.json mods ' +
18
+ "and configure a provider in admin → Settings → AI Providers.");
19
+ }
20
+ return svc;
21
+ }
22
+ export const AI_MCP_SERVICE = "aiMcpService";
23
+ export function aiMcpService(ctx) {
24
+ const svc = ctx.services[AI_MCP_SERVICE];
25
+ if (!svc) {
26
+ throw new Error('MCP tools need "@pattern-js/mod-ai" installed (it carries the MCP client). Add it to your pattern.config.json mods.');
27
+ }
28
+ return svc;
29
+ }
30
+ //# sourceMappingURL=model-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-service.js","sourceRoot":"","sources":["../src/model-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAmEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAEjD,2EAA2E;AAC3E,MAAM,UAAU,cAAc,CAAC,GAAc;IAC3C,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAA+B,CAAC;IACzE,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACb,2FAA2F;YACzF,8DAA8D,CACjE,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAcD,MAAM,CAAC,MAAM,cAAc,GAAG,cAAc,CAAC;AAE7C,MAAM,UAAU,YAAY,CAAC,GAAc;IACzC,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,cAAc,CAA6B,CAAC;IACrE,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACb,qHAAqH,CACtH,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
package/dist/types.d.ts CHANGED
@@ -32,6 +32,71 @@ export type MessagePart = z.infer<typeof messagePartSchema>;
32
32
  */
33
33
  export declare const historySchema: z.ZodArray<z.ZodUnknown>;
34
34
  export type History = unknown[];
35
+ /**
36
+ * A provider-neutral reference to a model. Plain JSON, structured-cloneable, it
37
+ * flows on a value port into every capability op and into an agent. The CAPABILITY
38
+ * layer (mod-ai) turns it into a concrete SDK model; the neutral layer only ever
39
+ * passes it around. Routing is first-class: `direct` (a native provider package +
40
+ * a provider key) or `gateway` (the Vercel AI Gateway, one key, `provider/model` ids).
41
+ */
42
+ export declare const modelRefSchema: z.ZodObject<{
43
+ kind: z.ZodLiteral<"model">;
44
+ routing: z.ZodEnum<{
45
+ direct: "direct";
46
+ gateway: "gateway";
47
+ }>;
48
+ modality: z.ZodDefault<z.ZodEnum<{
49
+ language: "language";
50
+ embedding: "embedding";
51
+ image: "image";
52
+ speech: "speech";
53
+ transcription: "transcription";
54
+ video: "video";
55
+ }>>;
56
+ provider: z.ZodString;
57
+ modelId: z.ZodString;
58
+ credential: z.ZodOptional<z.ZodString>;
59
+ alias: z.ZodOptional<z.ZodString>;
60
+ providerOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
61
+ }, z.core.$strip>;
62
+ export type ModelRef = z.infer<typeof modelRefSchema>;
63
+ /** Token accounting common to every generation, when the provider reports it. */
64
+ export declare const usageSchema: z.ZodObject<{
65
+ inputTokens: z.ZodOptional<z.ZodNumber>;
66
+ outputTokens: z.ZodOptional<z.ZodNumber>;
67
+ totalTokens: z.ZodOptional<z.ZodNumber>;
68
+ }, z.core.$strip>;
69
+ export type Usage = z.infer<typeof usageSchema>;
70
+ /**
71
+ * A provider-neutral chat message (parts-based content, reusing messagePartSchema).
72
+ * The agent loop owns history losslessly in this shape; mod-ai maps it to/from the
73
+ * AI SDK's message format. `tool` messages carry the call linkage; an `assistant`
74
+ * message may carry the tool calls it requested.
75
+ */
76
+ export declare const neutralMessageSchema: z.ZodObject<{
77
+ role: z.ZodEnum<{
78
+ system: "system";
79
+ user: "user";
80
+ assistant: "assistant";
81
+ tool: "tool";
82
+ }>;
83
+ content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
84
+ type: z.ZodLiteral<"text">;
85
+ text: z.ZodString;
86
+ }, z.core.$strip>, z.ZodObject<{
87
+ type: z.ZodLiteral<"image_ref">;
88
+ blobId: z.ZodString;
89
+ mime: z.ZodOptional<z.ZodString>;
90
+ }, z.core.$strip>]>>]>;
91
+ toolCallId: z.ZodOptional<z.ZodString>;
92
+ toolName: z.ZodOptional<z.ZodString>;
93
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
94
+ callId: z.ZodString;
95
+ toolName: z.ZodString;
96
+ args: z.ZodUnknown;
97
+ }, z.core.$strip>>>;
98
+ }, z.core.$strip>;
99
+ export type NeutralMessage = z.infer<typeof neutralMessageSchema>;
35
100
  export declare const toolRefSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
36
101
  origin: z.ZodLiteral<"workflow">;
37
102
  workflowId: z.ZodString;
@@ -88,8 +153,8 @@ export type ToolsetDescriptor = z.infer<typeof toolsetSchema>;
88
153
  export declare const guardrailSchema: z.ZodObject<{
89
154
  kind: z.ZodLiteral<"guardrail">;
90
155
  direction: z.ZodEnum<{
91
- input: "input";
92
156
  output: "output";
157
+ input: "input";
93
158
  }>;
94
159
  workflowId: z.ZodString;
95
160
  name: z.ZodString;
@@ -99,8 +164,8 @@ export interface AgentDescriptor {
99
164
  kind: "agent";
100
165
  name: string;
101
166
  instructions: string;
102
- model?: string;
103
- modelSettings?: Record<string, unknown>;
167
+ /** The model to run on (wire an ai.model node). Undefined = the configured default. */
168
+ model?: ModelRef;
104
169
  tools?: ToolsetDescriptor;
105
170
  guardrails?: GuardrailDescriptor[];
106
171
  /** Other agents this one may hand off to. */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB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