@fungi.computer/mule 0.1.0 → 0.1.1
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/THIRD_PARTY_NOTICES +8 -3
- package/dist/contract.d.ts +2 -2
- package/dist/effect.d.ts +5 -2
- package/dist/effect.js +6 -3
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -0
- package/dist/pi-options.d.ts +6 -0
- package/dist/pi-options.js +35 -0
- package/dist/provider-data.d.ts +3 -0
- package/dist/provider-data.js +17 -0
- package/dist/provider-model.d.ts +3 -0
- package/dist/provider-model.js +18 -0
- package/dist/provider-status.d.ts +1 -1
- package/dist/provider.d.ts +3 -0
- package/dist/provider.js +7 -0
- package/dist/testing.d.ts +47 -4
- package/dist/testing.js +15 -7
- package/dist/types.d.ts +381 -0
- package/dist/types.js +1 -0
- package/docs/api/effect.md +1674 -17
- package/docs/api/index.md +100 -41
- package/docs/api/testing.md +232 -6
- package/package.json +1 -1
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import type { TSchema } from "typebox";
|
|
2
|
+
import type { AnthropicMessagesCompat, BedrockCompat, MistralConversationsCompat, OpenAICompletionsCompat, OpenAIResponsesCompat } from "@earendil-works/pi-ai/providers/compat-schema";
|
|
3
|
+
import type { CacheRetention, ModelCost, ModelInputLimits, ModelInputModality, ModelPromptCache, ThinkingLevelMap } from "@earendil-works/pi-ai/providers/model-schema";
|
|
4
|
+
/** Provider-neutral reasoning effort requested by a caller. */
|
|
5
|
+
export type ThinkingLevel = "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
6
|
+
/** Effective reasoning effort, including disabled thinking. */
|
|
7
|
+
export type ModelThinkingLevel = "off" | ThinkingLevel;
|
|
8
|
+
/** Built-in chat APIs recognized by the pinned Pi adapter. */
|
|
9
|
+
export type KnownApi = "openai-completions" | "mistral-conversations" | "openai-responses" | "azure-openai-responses" | "openai-codex-responses" | "anthropic-messages" | "bedrock-converse-stream" | "google-generative-ai" | "google-vertex" | "pi-messages";
|
|
10
|
+
/** Built-in or caller-defined chat API identifier. */
|
|
11
|
+
export type Api = KnownApi | (string & {});
|
|
12
|
+
/** Provider identifier carried with a model or assistant message. */
|
|
13
|
+
export type ProviderId = string;
|
|
14
|
+
/** Provider-neutral choice to allow or disable tools. */
|
|
15
|
+
export type ToolChoice = "auto" | "none";
|
|
16
|
+
/** Provider sampling fields passed through unchanged. */
|
|
17
|
+
export type SamplingParams = JsonObject;
|
|
18
|
+
/** Sampling overrides selected by reasoning effort. */
|
|
19
|
+
export type SamplingParamsByThinkingLevel = Partial<Record<ModelThinkingLevel, SamplingParams>>;
|
|
20
|
+
/** Token budgets for providers that meter reasoning separately. */
|
|
21
|
+
export type ThinkingBudgets = {
|
|
22
|
+
minimal?: number;
|
|
23
|
+
low?: number;
|
|
24
|
+
medium?: number;
|
|
25
|
+
high?: number;
|
|
26
|
+
};
|
|
27
|
+
/** Preferred provider stream transport. */
|
|
28
|
+
export type Transport = "sse" | "websocket" | "websocket-cached" | "auto";
|
|
29
|
+
/** Request-scoped provider environment overrides. */
|
|
30
|
+
export type ProviderEnv = Record<string, string>;
|
|
31
|
+
/** Provider headers; null removes a default header. */
|
|
32
|
+
export type ProviderHeaders = Record<string, string | null>;
|
|
33
|
+
/** Fetch implementation supplied to the provider adapter. */
|
|
34
|
+
export type FetchFunction = typeof globalThis.fetch;
|
|
35
|
+
/** HTTP status and headers observed before stream consumption. */
|
|
36
|
+
export type ProviderResponse = {
|
|
37
|
+
status: number;
|
|
38
|
+
headers: Record<string, string>;
|
|
39
|
+
};
|
|
40
|
+
/** Authentication, transport and lifecycle hooks for one provider request. */
|
|
41
|
+
export type ProviderRequestOptions<TModel = Model<Api>> = {
|
|
42
|
+
signal?: AbortSignal;
|
|
43
|
+
telemetryContext?: TelemetryContext;
|
|
44
|
+
apiKey?: string;
|
|
45
|
+
/** Override HTTP transport for this request. */
|
|
46
|
+
fetch?: FetchFunction;
|
|
47
|
+
env?: ProviderEnv;
|
|
48
|
+
/** Observe or replace the provider payload before dispatch. */
|
|
49
|
+
onPayload?: (payload: ProviderData, model: TModel) => ProviderData | undefined | Promise<ProviderData | undefined>;
|
|
50
|
+
/** Observe status and headers before provider stream consumption. */
|
|
51
|
+
onResponse?: (response: ProviderResponse, model: TModel) => void | Promise<void>;
|
|
52
|
+
headers?: ProviderHeaders;
|
|
53
|
+
timeoutMs?: number;
|
|
54
|
+
maxRetries?: number;
|
|
55
|
+
maxRetryDelayMs?: number;
|
|
56
|
+
};
|
|
57
|
+
/** Common provider stream controls, independent of any SDK. */
|
|
58
|
+
export type StreamOptions = {
|
|
59
|
+
/** Observe an adapter-parsed event before Pi normalizes it. */
|
|
60
|
+
onProviderStreamEvent?: (data: ProviderData, model: Model<Api>) => void | Promise<void>;
|
|
61
|
+
temperature?: number;
|
|
62
|
+
samplingParams?: SamplingParams;
|
|
63
|
+
maxTokens?: number;
|
|
64
|
+
transport?: Transport;
|
|
65
|
+
cacheRetention?: CacheRetention;
|
|
66
|
+
sessionId?: string;
|
|
67
|
+
websocketConnectTimeoutMs?: number;
|
|
68
|
+
metadata?: JsonObject;
|
|
69
|
+
} & ProviderRequestOptions;
|
|
70
|
+
/** Provider-neutral model request options used by Mule. */
|
|
71
|
+
export type SimpleStreamOptions = {
|
|
72
|
+
toolChoice?: ToolChoice;
|
|
73
|
+
reasoning?: ThinkingLevel;
|
|
74
|
+
deferred?: boolean | {
|
|
75
|
+
window?: "15m" | "1h" | "24h";
|
|
76
|
+
};
|
|
77
|
+
thinkingBudgets?: ThinkingBudgets;
|
|
78
|
+
} & StreamOptions;
|
|
79
|
+
/** Text block with an optional provider continuity signature. */
|
|
80
|
+
export type TextContent = {
|
|
81
|
+
type: "text";
|
|
82
|
+
text: string;
|
|
83
|
+
textSignature?: string;
|
|
84
|
+
};
|
|
85
|
+
/** Reasoning block, including opaque redacted provider thinking. */
|
|
86
|
+
export type ThinkingContent = {
|
|
87
|
+
type: "thinking";
|
|
88
|
+
thinking: string;
|
|
89
|
+
thinkingSignature?: string;
|
|
90
|
+
redacted?: boolean;
|
|
91
|
+
};
|
|
92
|
+
/** Base64 image bytes with their media type. */
|
|
93
|
+
export type ImageContent = {
|
|
94
|
+
type: "image";
|
|
95
|
+
data: string;
|
|
96
|
+
mimeType: string;
|
|
97
|
+
};
|
|
98
|
+
/** Model-requested tool invocation with JSON arguments. */
|
|
99
|
+
export type ToolCall = {
|
|
100
|
+
type: "toolCall";
|
|
101
|
+
id: string;
|
|
102
|
+
name: string;
|
|
103
|
+
arguments: JsonObject;
|
|
104
|
+
thoughtSignature?: string;
|
|
105
|
+
namespace?: string;
|
|
106
|
+
argumentsError?: string;
|
|
107
|
+
};
|
|
108
|
+
/** Token counts and provider costs for one response or tool result. */
|
|
109
|
+
export type Usage = {
|
|
110
|
+
input: number;
|
|
111
|
+
output: number;
|
|
112
|
+
cacheRead: number;
|
|
113
|
+
cacheWrite: number;
|
|
114
|
+
cacheWrite1h?: number;
|
|
115
|
+
reasoning?: number;
|
|
116
|
+
totalTokens: number;
|
|
117
|
+
cost: {
|
|
118
|
+
input: number;
|
|
119
|
+
output: number;
|
|
120
|
+
cacheRead: number;
|
|
121
|
+
cacheWrite: number;
|
|
122
|
+
total: number;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
/** Provider outcome for an assistant response. */
|
|
126
|
+
export type StopReason = "pending" | "stop" | "length" | "toolUse" | "error" | "aborted" | "deferred";
|
|
127
|
+
/** JSON data carried by messages and tool results. */
|
|
128
|
+
export type JsonValue = null | boolean | number | string | readonly JsonValue[] | JsonObject;
|
|
129
|
+
/** Provider request/event values, including optional fields, binary bytes and cancellation. */
|
|
130
|
+
export type ProviderValue = undefined | null | boolean | number | string | Uint8Array | AbortSignal | readonly ProviderValue[] | ProviderData;
|
|
131
|
+
/** Parsed provider request or event fields; Pi owns the provider-specific grammar. */
|
|
132
|
+
export type ProviderData = {
|
|
133
|
+
[key: string]: ProviderValue;
|
|
134
|
+
};
|
|
135
|
+
/** Named JSON properties in tool arguments or message metadata. */
|
|
136
|
+
export type JsonObject = {
|
|
137
|
+
[key: string]: JsonValue;
|
|
138
|
+
};
|
|
139
|
+
/** Provider receipt used to recover a deferred assistant response. */
|
|
140
|
+
export type DeferredHandle = {
|
|
141
|
+
provider: string;
|
|
142
|
+
modelId: string;
|
|
143
|
+
api: string;
|
|
144
|
+
id: string;
|
|
145
|
+
expiresAt?: number;
|
|
146
|
+
pollAfterMs?: number;
|
|
147
|
+
data?: JsonValue;
|
|
148
|
+
};
|
|
149
|
+
/** Prompt and tool-set update at a point in the transcript. */
|
|
150
|
+
export type SystemMessage = {
|
|
151
|
+
role: "system";
|
|
152
|
+
content: string | TextContent[];
|
|
153
|
+
sections?: Record<string, string | null>;
|
|
154
|
+
toolsAdded?: Tool[];
|
|
155
|
+
toolsRemoved?: ToolReference[];
|
|
156
|
+
timestamp: number;
|
|
157
|
+
};
|
|
158
|
+
/** User text and image input with its timestamp. */
|
|
159
|
+
export type UserMessage = {
|
|
160
|
+
role: "user";
|
|
161
|
+
content: string | (TextContent | ImageContent)[];
|
|
162
|
+
timestamp: number;
|
|
163
|
+
};
|
|
164
|
+
/** Provider response, usage and terminal reason, preserved by Mule. */
|
|
165
|
+
export type AssistantMessage = {
|
|
166
|
+
role: "assistant";
|
|
167
|
+
content: (TextContent | ThinkingContent | ToolCall)[];
|
|
168
|
+
api: Api;
|
|
169
|
+
provider: ProviderId;
|
|
170
|
+
model: string;
|
|
171
|
+
responseModel?: string;
|
|
172
|
+
responseId?: string;
|
|
173
|
+
providerThinkingLevel?: string;
|
|
174
|
+
thinkingLevel?: ModelThinkingLevel;
|
|
175
|
+
diagnostics?: AssistantMessageDiagnostic[];
|
|
176
|
+
usage: Usage;
|
|
177
|
+
stopReason: StopReason;
|
|
178
|
+
deferred?: DeferredHandle;
|
|
179
|
+
errorMessage?: string;
|
|
180
|
+
rawStopReason?: string;
|
|
181
|
+
endTurn?: boolean;
|
|
182
|
+
timestamp: number;
|
|
183
|
+
durationMs?: number;
|
|
184
|
+
};
|
|
185
|
+
/** Bounded evidence of a tool invocation made inside another tool. */
|
|
186
|
+
export type NestedToolCallRecord = {
|
|
187
|
+
id: string;
|
|
188
|
+
name: string;
|
|
189
|
+
arguments?: JsonObject;
|
|
190
|
+
argumentsBytes?: number;
|
|
191
|
+
status: "ok" | "error" | "unfinished";
|
|
192
|
+
durationMs?: number;
|
|
193
|
+
error?: string;
|
|
194
|
+
};
|
|
195
|
+
/** Recorded nested invocations and whether the record is complete. */
|
|
196
|
+
export type NestedToolCalls = {
|
|
197
|
+
calls: NestedToolCallRecord[];
|
|
198
|
+
complete: boolean;
|
|
199
|
+
};
|
|
200
|
+
/** Correlated tool output with optional JSON details and usage. */
|
|
201
|
+
export type ToolResultMessage = {
|
|
202
|
+
role: "toolResult";
|
|
203
|
+
toolCallId: string;
|
|
204
|
+
toolName: string;
|
|
205
|
+
content: (TextContent | ImageContent)[];
|
|
206
|
+
details?: JsonValue;
|
|
207
|
+
usage?: Usage;
|
|
208
|
+
nestedCalls?: NestedToolCalls;
|
|
209
|
+
isError: boolean;
|
|
210
|
+
timestamp: number;
|
|
211
|
+
durationMs?: number;
|
|
212
|
+
};
|
|
213
|
+
/** One system, user, assistant or tool-result transcript entry. */
|
|
214
|
+
export type Message = SystemMessage | UserMessage | AssistantMessage | ToolResultMessage;
|
|
215
|
+
/** Provider grammar formats available for constrained sampling. */
|
|
216
|
+
export type GrammarFormat = "openai_lark" | "openai_regex";
|
|
217
|
+
/** Grammar text supplied for each supported provider format. */
|
|
218
|
+
export type GrammarVariants = Partial<Record<GrammarFormat, string>>;
|
|
219
|
+
/** Provider constraint for a tool declaration. */
|
|
220
|
+
export type ConstrainedSamplingConfig = {
|
|
221
|
+
type: "json_schema";
|
|
222
|
+
strict: "prefer" | "require";
|
|
223
|
+
} | {
|
|
224
|
+
type: "grammar";
|
|
225
|
+
variants: GrammarVariants;
|
|
226
|
+
};
|
|
227
|
+
/** Model-visible tool name, description and TypeBox argument schema. */
|
|
228
|
+
export type Tool<TParameters extends TSchema = TSchema> = {
|
|
229
|
+
name: string;
|
|
230
|
+
description: string;
|
|
231
|
+
parameters: TParameters;
|
|
232
|
+
constrainedSampling?: false | ConstrainedSamplingConfig;
|
|
233
|
+
};
|
|
234
|
+
/** Named tool removed by a transcript system update. */
|
|
235
|
+
export type ToolReference = {
|
|
236
|
+
name: string;
|
|
237
|
+
};
|
|
238
|
+
/** Model request context; Pi adapters normalize it before provider dispatch. */
|
|
239
|
+
export type Context = {
|
|
240
|
+
systemPrompt?: string;
|
|
241
|
+
messages: Message[];
|
|
242
|
+
tools?: Tool[];
|
|
243
|
+
};
|
|
244
|
+
/** Partial updates and the terminal event for an assistant stream. */
|
|
245
|
+
export type AssistantMessageEvent = {
|
|
246
|
+
type: "start";
|
|
247
|
+
partial: AssistantMessage;
|
|
248
|
+
} | {
|
|
249
|
+
type: "text_start";
|
|
250
|
+
contentIndex: number;
|
|
251
|
+
partial: AssistantMessage;
|
|
252
|
+
} | {
|
|
253
|
+
type: "text_delta";
|
|
254
|
+
contentIndex: number;
|
|
255
|
+
delta: string;
|
|
256
|
+
partial: AssistantMessage;
|
|
257
|
+
} | {
|
|
258
|
+
type: "text_end";
|
|
259
|
+
contentIndex: number;
|
|
260
|
+
content: string;
|
|
261
|
+
partial: AssistantMessage;
|
|
262
|
+
} | {
|
|
263
|
+
type: "thinking_start";
|
|
264
|
+
contentIndex: number;
|
|
265
|
+
partial: AssistantMessage;
|
|
266
|
+
} | {
|
|
267
|
+
type: "thinking_delta";
|
|
268
|
+
contentIndex: number;
|
|
269
|
+
delta: string;
|
|
270
|
+
partial: AssistantMessage;
|
|
271
|
+
} | {
|
|
272
|
+
type: "thinking_end";
|
|
273
|
+
contentIndex: number;
|
|
274
|
+
content: string;
|
|
275
|
+
partial: AssistantMessage;
|
|
276
|
+
} | {
|
|
277
|
+
type: "toolcall_start";
|
|
278
|
+
contentIndex: number;
|
|
279
|
+
partial: AssistantMessage;
|
|
280
|
+
} | {
|
|
281
|
+
type: "toolcall_delta";
|
|
282
|
+
contentIndex: number;
|
|
283
|
+
delta: string;
|
|
284
|
+
partial: AssistantMessage;
|
|
285
|
+
} | {
|
|
286
|
+
type: "toolcall_end";
|
|
287
|
+
contentIndex: number;
|
|
288
|
+
toolCall: ToolCall;
|
|
289
|
+
partial: AssistantMessage;
|
|
290
|
+
} | {
|
|
291
|
+
type: "done";
|
|
292
|
+
reason: Extract<StopReason, "stop" | "length" | "toolUse" | "deferred">;
|
|
293
|
+
message: AssistantMessage;
|
|
294
|
+
} | {
|
|
295
|
+
type: "error";
|
|
296
|
+
reason: Extract<StopReason, "aborted" | "error">;
|
|
297
|
+
error: AssistantMessage;
|
|
298
|
+
};
|
|
299
|
+
/** Catalog fields shared by chat model definitions. */
|
|
300
|
+
export type BaseModel<TApi extends string> = {
|
|
301
|
+
id: string;
|
|
302
|
+
name: string;
|
|
303
|
+
api: TApi;
|
|
304
|
+
provider: ProviderId;
|
|
305
|
+
baseUrl: string;
|
|
306
|
+
input: ModelInputModality[];
|
|
307
|
+
inputLimits?: ModelInputLimits;
|
|
308
|
+
cost: ModelCost;
|
|
309
|
+
headers?: Record<string, string>;
|
|
310
|
+
};
|
|
311
|
+
/** Chat model configuration accepted by Mule and its Pi adapter. */
|
|
312
|
+
export type Model<TApi extends Api> = {
|
|
313
|
+
type?: "chat";
|
|
314
|
+
reasoning: boolean;
|
|
315
|
+
thinkingLevelMap?: ThinkingLevelMap;
|
|
316
|
+
promptCache?: ModelPromptCache;
|
|
317
|
+
contextWindow: number;
|
|
318
|
+
maxTokens: number;
|
|
319
|
+
samplingParams?: SamplingParams;
|
|
320
|
+
samplingParamsByThinkingLevel?: SamplingParamsByThinkingLevel;
|
|
321
|
+
compat?: TApi extends "openai-completions" ? OpenAICompletionsCompat : TApi extends "openai-responses" | "azure-openai-responses" | "openai-codex-responses" ? OpenAIResponsesCompat : TApi extends "anthropic-messages" ? AnthropicMessagesCompat : TApi extends "bedrock-converse-stream" ? BedrockCompat : TApi extends "mistral-conversations" ? MistralConversationsCompat : never;
|
|
322
|
+
} & BaseModel<TApi>;
|
|
323
|
+
/** Serializable diagnostic information retained with an assistant message. */
|
|
324
|
+
export type DiagnosticErrorInfo = {
|
|
325
|
+
name?: string;
|
|
326
|
+
message: string;
|
|
327
|
+
stack?: string;
|
|
328
|
+
code?: string | number;
|
|
329
|
+
};
|
|
330
|
+
/** Timestamped provider diagnostic with optional JSON details. */
|
|
331
|
+
export type AssistantMessageDiagnostic = {
|
|
332
|
+
type: string;
|
|
333
|
+
timestamp: number;
|
|
334
|
+
error?: DiagnosticErrorInfo;
|
|
335
|
+
details?: JsonObject;
|
|
336
|
+
};
|
|
337
|
+
/** Only the stream operations consumed by Mule. Pi's concrete stream satisfies this port. */
|
|
338
|
+
export type AssistantMessageEventStream = {
|
|
339
|
+
/** Await the authoritative final assistant message. */
|
|
340
|
+
result(): Promise<AssistantMessage>;
|
|
341
|
+
} & AsyncIterable<AssistantMessageEvent>;
|
|
342
|
+
/** Bounded assistant-call retries with capped exponential delays. */
|
|
343
|
+
export type RetryPolicy = {
|
|
344
|
+
enabled: boolean;
|
|
345
|
+
maxRetries: number;
|
|
346
|
+
baseDelayMs: number;
|
|
347
|
+
maxAgentDelayMs?: number;
|
|
348
|
+
};
|
|
349
|
+
/** Scalar or homogeneous-array telemetry attribute. */
|
|
350
|
+
export type AttributeValue = string | number | boolean | readonly string[] | readonly number[] | readonly boolean[];
|
|
351
|
+
/** Named telemetry attributes, with undefined values omitted by the owner. */
|
|
352
|
+
export type SpanAttributes = Record<string, AttributeValue | undefined>;
|
|
353
|
+
/** Name and initial attributes of a request telemetry span. */
|
|
354
|
+
export type SpanOptions = {
|
|
355
|
+
name: string;
|
|
356
|
+
attributes?: SpanAttributes;
|
|
357
|
+
};
|
|
358
|
+
/** Successful or failed telemetry completion. */
|
|
359
|
+
export type SpanStatus = {
|
|
360
|
+
status: "ok";
|
|
361
|
+
} | {
|
|
362
|
+
status: "error";
|
|
363
|
+
error?: {
|
|
364
|
+
name: string;
|
|
365
|
+
message: string;
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
/** Parent context through which a provider opens telemetry spans. */
|
|
369
|
+
export type TelemetryContext = {
|
|
370
|
+
/** Run provider work under a child span. */
|
|
371
|
+
startSpan<T>(options: SpanOptions, callback: (span: TelemetrySpan) => T | Promise<T>): Promise<T>;
|
|
372
|
+
};
|
|
373
|
+
/** Provider telemetry span with events, attributes and completion status. */
|
|
374
|
+
export type TelemetrySpan = {
|
|
375
|
+
/** Record a timestamped event on this span. */
|
|
376
|
+
addEvent(name: string, attributes?: SpanAttributes): void;
|
|
377
|
+
/** Add or replace attributes on this span. */
|
|
378
|
+
setAttributes(attributes: SpanAttributes): void;
|
|
379
|
+
/** Record the completion status of this span. */
|
|
380
|
+
setStatus(status: SpanStatus): void;
|
|
381
|
+
} & TelemetryContext;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|