@fungi.computer/mule 0.1.0 → 0.2.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/docs/api/index.md CHANGED
@@ -24,15 +24,16 @@ Pi's model stream function, supplied explicitly by the caller.
24
24
 
25
25
  #### Parameters
26
26
 
27
- | Parameter | Type |
28
- | ---------- | --------------------- |
29
- | `model` | `Model`\<`Api`\> |
30
- | `context` | `TranscriptContext` |
31
- | `options?` | `SimpleStreamOptions` |
27
+ | Parameter | Type |
28
+ | ---------- | ------------------------------------------------------ |
29
+ | `model` | [`Model`](effect.md#model-1)\<[`Api`](effect.md#api)\> |
30
+ | `context` | [`Context`](effect.md#context) |
31
+ | `options?` | [`SimpleStreamOptions`](effect.md#simplestreamoptions) |
32
32
 
33
33
  #### Returns
34
34
 
35
- \| `AssistantMessageEventStream` \| `Promise`\<`AssistantMessageEventStream`\>
35
+ \| [`AssistantMessageEventStream`](effect.md#assistantmessageeventstream) \|
36
+ `Promise`\<[`AssistantMessageEventStream`](effect.md#assistantmessageeventstream)\>
36
37
 
37
38
  ---
38
39
 
@@ -128,7 +129,9 @@ Result produced by a tool before Mule forms Pi's correlated result message.
128
129
  ##### content
129
130
 
130
131
  ```ts
131
- readonly content: (TextContent | ImageContent)[];
132
+ readonly content: (
133
+ | TextContent
134
+ | ImageContent)[];
132
135
  ```
133
136
 
134
137
  ##### data?
@@ -410,14 +413,14 @@ Lifecycle emitted around Pi values. Pi messages and events are not rewritten.
410
413
  }
411
414
  ```
412
415
 
413
- | Name | Type | Description |
414
- | --------- | ------------------------------- | --------------------------------------------------------------- |
415
- | `type` | `"message_end"` | - |
416
- | `run` | [`MuleIdentity`](#muleidentity) | - |
417
- | `turn` | [`MuleIdentity`](#muleidentity) | - |
418
- | `message` | [`MuleIdentity`](#muleidentity) | - |
419
- | `value` | `Message` | - |
420
- | `data?` | `JsonValue` | Application payload independent of the completed model message. |
416
+ | Name | Type | Description |
417
+ | --------- | ---------------------------------- | --------------------------------------------------------------- |
418
+ | `type` | `"message_end"` | - |
419
+ | `run` | [`MuleIdentity`](#muleidentity) | - |
420
+ | `turn` | [`MuleIdentity`](#muleidentity) | - |
421
+ | `message` | [`MuleIdentity`](#muleidentity) | - |
422
+ | `value` | [`Message`](effect.md#message) | - |
423
+ | `data?` | [`JsonValue`](effect.md#jsonvalue) | Application payload independent of the completed model message. |
421
424
 
422
425
  ---
423
426
 
@@ -559,12 +562,12 @@ Durable evidence for a call in an interrupted assistant turn.
559
562
  }
560
563
  ```
561
564
 
562
- | Name | Type | Description |
563
- | ---------- | ----------------------------------- | ------------------------------------------------------ |
564
- | `call` | `ToolCall` | - |
565
- | `state` | `"completed"` | - |
566
- | `result` | [`MuleToolResult`](#muletoolresult) | - |
567
- | `message?` | `ToolResultMessage` | Present when the transcript message was committed too. |
565
+ | Name | Type | Description |
566
+ | ---------- | -------------------------------------------------- | ------------------------------------------------------ |
567
+ | `call` | [`ToolCall`](effect.md#toolcall) | - |
568
+ | `state` | `"completed"` | - |
569
+ | `result` | [`MuleToolResult`](#muletoolresult) | - |
570
+ | `message?` | [`ToolResultMessage`](effect.md#toolresultmessage) | Present when the transcript message was committed too. |
568
571
 
569
572
  ---
570
573
 
@@ -654,6 +657,18 @@ readonly optional modelStreamIdleTimeoutMs?: number;
654
657
 
655
658
  Maximum silence between provider stream events, in milliseconds.
656
659
 
660
+ ##### modelStreamLimits?
661
+
662
+ ```ts
663
+ readonly optional modelStreamLimits?: Partial<{
664
+ firstEventMs: number;
665
+ attemptMs: number;
666
+ outputBytes: number;
667
+ }>;
668
+ ```
669
+
670
+ Trusted per-attempt safety limits may only tighten Mule's defaults.
671
+
657
672
  ##### toolExecution?
658
673
 
659
674
  ```ts
@@ -683,9 +698,9 @@ retry; unknown messages return false, never a decision from prose.
683
698
 
684
699
  ###### Parameters
685
700
 
686
- | Parameter | Type |
687
- | --------- | ------------------ |
688
- | `message` | `AssistantMessage` |
701
+ | Parameter | Type |
702
+ | --------- | ------------------------------------------------ |
703
+ | `message` | [`AssistantMessage`](effect.md#assistantmessage) |
689
704
 
690
705
  ###### Returns
691
706
 
@@ -701,9 +716,9 @@ Provider's bounded Retry-After evidence for the last assistant error.
701
716
 
702
717
  ###### Parameters
703
718
 
704
- | Parameter | Type |
705
- | --------- | ------------------ |
706
- | `message` | `AssistantMessage` |
719
+ | Parameter | Type |
720
+ | --------- | ------------------------------------------------ |
721
+ | `message` | [`AssistantMessage`](effect.md#assistantmessage) |
707
722
 
708
723
  ###### Returns
709
724
 
@@ -751,6 +766,14 @@ readonly message: AssistantMessage;
751
766
  readonly messages: readonly Message[];
752
767
  ```
753
768
 
769
+ ##### modelLimitReason?
770
+
771
+ ```ts
772
+ readonly optional modelLimitReason?: string;
773
+ ```
774
+
775
+ Mule-owned limit diagnostic, not untrusted provider prose.
776
+
754
777
  ---
755
778
 
756
779
  ### MulePromiseListener
@@ -849,10 +872,10 @@ Decode and authorize one exact Pi tool call before it can execute.
849
872
 
850
873
  ###### Parameters
851
874
 
852
- | Parameter | Type |
853
- | --------- | ------------- |
854
- | `call` | `ToolCall` |
855
- | `signal` | `AbortSignal` |
875
+ | Parameter | Type |
876
+ | --------- | -------------------------------- |
877
+ | `call` | [`ToolCall`](effect.md#toolcall) |
878
+ | `signal` | `AbortSignal` |
856
879
 
857
880
  ###### Returns
858
881
 
@@ -870,13 +893,13 @@ Inputs for one complete Pi model/tool loop through the Promise facade.
870
893
 
871
894
  #### Type Declaration
872
895
 
873
- | Name | Type | Description |
874
- | ------------------------ | -------------------------------------------------------------- | -------------------------------------------------------------------- |
875
- | `tools?` | readonly [`MuleTool`](#muletool)[] | - |
876
- | `resolveApiKey()?` | (`provider`, `signal`) => `Promise`\<`string` \| `undefined`\> | Resolve a fresh provider credential immediately before each Pi call. |
877
- | `getSteeringMessages()?` | (`signal`) => `Promise`\<readonly `Message`[]\> | Pull messages that should steer the active run at Pi's safe point. |
878
- | `getFollowUpMessages()?` | (`signal`) => `Promise`\<readonly `Message`[]\> | Pull messages queued until the run would otherwise finish. |
879
- | `shouldStopAfterTurn()?` | (`turn`, `signal`) => `Promise`\<`boolean`\> | Request a graceful stop after the current Pi turn has fully settled. |
896
+ | Name | Type | Description |
897
+ | ------------------------ | -------------------------------------------------------------------- | -------------------------------------------------------------------- |
898
+ | `tools?` | readonly [`MuleTool`](#muletool)[] | - |
899
+ | `resolveApiKey()?` | (`provider`, `signal`) => `Promise`\<`string` \| `undefined`\> | Resolve a fresh provider credential immediately before each Pi call. |
900
+ | `getSteeringMessages()?` | (`signal`) => `Promise`\<readonly [`Message`](effect.md#message)[]\> | Pull messages that should steer the active run at Pi's safe point. |
901
+ | `getFollowUpMessages()?` | (`signal`) => `Promise`\<readonly [`Message`](effect.md#message)[]\> | Pull messages queued until the run would otherwise finish. |
902
+ | `shouldStopAfterTurn()?` | (`turn`, `signal`) => `Promise`\<`boolean`\> | Request a graceful stop after the current Pi turn has fully settled. |
880
903
 
881
904
  ---
882
905
 
@@ -959,8 +982,64 @@ const mule: Mule;
959
982
 
960
983
  Default Promise-facing Mule interface.
961
984
 
985
+ ---
986
+
987
+ ### streamModel
988
+
989
+ ```ts
990
+ const streamModel: MuleStreamFunction;
991
+ ```
992
+
993
+ Pi's maintained stream behind Mule's structural provider port.
994
+
962
995
  ## Functions
963
996
 
997
+ ### decodeProviderData()
998
+
999
+ ```ts
1000
+ function decodeProviderData(data): ProviderData;
1001
+ ```
1002
+
1003
+ Decode Pi's parsed request/event data before it enters an owned hook.
1004
+
1005
+ #### Parameters
1006
+
1007
+ | Parameter | Type |
1008
+ | --------- | --------- |
1009
+ | `data` | `unknown` |
1010
+
1011
+ #### Returns
1012
+
1013
+ [`ProviderData`](effect.md#providerdata)
1014
+
1015
+ ---
1016
+
1017
+ ### normalizeModel()
1018
+
1019
+ ```ts
1020
+ function normalizeModel<TApi>(model): Model<TApi>;
1021
+ ```
1022
+
1023
+ Validate a catalog model's opaque sampling fields before it enters Mule.
1024
+
1025
+ #### Type Parameters
1026
+
1027
+ | Type Parameter |
1028
+ | --------------------------------------- |
1029
+ | `TApi` _extends_ [`Api`](effect.md#api) |
1030
+
1031
+ #### Parameters
1032
+
1033
+ | Parameter | Type |
1034
+ | --------- | --------------------------------------------------------------------------------------------------------- |
1035
+ | `model` | `Omit`\<[`Model`](effect.md#model-1)\<`TApi`\>, `"samplingParams"` \| `"samplingParamsByThinkingLevel"`\> |
1036
+
1037
+ #### Returns
1038
+
1039
+ [`Model`](effect.md#model-1)\<`TApi`\>
1040
+
1041
+ ---
1042
+
964
1043
  ### observeProviderStatus()
965
1044
 
966
1045
  ```ts
@@ -972,9 +1051,9 @@ decoding; this module retains no provider prose.
972
1051
 
973
1052
  #### Parameters
974
1053
 
975
- | Parameter | Type |
976
- | ---------- | ----------------------------------------------------------------------- |
977
- | `options?` | `Pick`\<`SimpleStreamOptions`, `"onProviderStreamEvent"` \| `"fetch"`\> |
1054
+ | Parameter | Type |
1055
+ | ---------- | -------------------------------------------------------------------------------------------------------- |
1056
+ | `options?` | `Pick`\<[`SimpleStreamOptions`](effect.md#simplestreamoptions), `"onProviderStreamEvent"` \| `"fetch"`\> |
978
1057
 
979
1058
  #### Returns
980
1059
 
@@ -10,15 +10,241 @@
10
10
 
11
11
  ## Type Aliases
12
12
 
13
+ ### FauxModelDefinition
14
+
15
+ ```ts
16
+ type FauxModelDefinition = object;
17
+ ```
18
+
19
+ Credential-free model definition for the scripted provider.
20
+
21
+ #### Properties
22
+
23
+ ##### id
24
+
25
+ ```ts
26
+ id: string;
27
+ ```
28
+
29
+ ##### name?
30
+
31
+ ```ts
32
+ optional name?: string;
33
+ ```
34
+
35
+ ##### reasoning?
36
+
37
+ ```ts
38
+ optional reasoning?: boolean;
39
+ ```
40
+
41
+ ##### input?
42
+
43
+ ```ts
44
+ optional input?: ("text" | "image")[];
45
+ ```
46
+
47
+ ##### inputLimits?
48
+
49
+ ```ts
50
+ optional inputLimits?: Model<Api>["inputLimits"];
51
+ ```
52
+
53
+ ##### cost?
54
+
55
+ ```ts
56
+ optional cost?: object;
57
+ ```
58
+
59
+ ###### input
60
+
61
+ ```ts
62
+ input: number;
63
+ ```
64
+
65
+ ###### output
66
+
67
+ ```ts
68
+ output: number;
69
+ ```
70
+
71
+ ###### cacheRead
72
+
73
+ ```ts
74
+ cacheRead: number;
75
+ ```
76
+
77
+ ###### cacheWrite
78
+
79
+ ```ts
80
+ cacheWrite: number;
81
+ ```
82
+
83
+ ##### contextWindow?
84
+
85
+ ```ts
86
+ optional contextWindow?: number;
87
+ ```
88
+
89
+ ##### maxTokens?
90
+
91
+ ```ts
92
+ optional maxTokens?: number;
93
+ ```
94
+
95
+ ---
96
+
97
+ ### RegisterFauxProviderOptions
98
+
99
+ ```ts
100
+ type RegisterFauxProviderOptions = object;
101
+ ```
102
+
103
+ Scripted provider configuration, independent of provider SDK declarations.
104
+
105
+ #### Properties
106
+
107
+ ##### api?
108
+
109
+ ```ts
110
+ optional api?: string;
111
+ ```
112
+
113
+ ##### provider?
114
+
115
+ ```ts
116
+ optional provider?: string;
117
+ ```
118
+
119
+ ##### models?
120
+
121
+ ```ts
122
+ optional models?: FauxModelDefinition[];
123
+ ```
124
+
125
+ ##### deferred?
126
+
127
+ ```ts
128
+ optional deferred?: object;
129
+ ```
130
+
131
+ ###### pendingFetches?
132
+
133
+ ```ts
134
+ optional pendingFetches?: number;
135
+ ```
136
+
137
+ ###### pollAfterMs?
138
+
139
+ ```ts
140
+ optional pollAfterMs?: number;
141
+ ```
142
+
143
+ ##### tokensPerSecond?
144
+
145
+ ```ts
146
+ optional tokensPerSecond?: number;
147
+ ```
148
+
149
+ ##### tokenSize?
150
+
151
+ ```ts
152
+ optional tokenSize?: object;
153
+ ```
154
+
155
+ ###### min?
156
+
157
+ ```ts
158
+ optional min?: number;
159
+ ```
160
+
161
+ ###### max?
162
+
163
+ ```ts
164
+ optional max?: number;
165
+ ```
166
+
167
+ ---
168
+
169
+ ### FauxProviderState
170
+
171
+ ```ts
172
+ type FauxProviderState = object;
173
+ ```
174
+
175
+ Counters retained by the scripted provider.
176
+
177
+ #### Properties
178
+
179
+ ##### callCount
180
+
181
+ ```ts
182
+ callCount: number;
183
+ ```
184
+
185
+ ##### deferredFetchCount
186
+
187
+ ```ts
188
+ deferredFetchCount: number;
189
+ ```
190
+
191
+ ##### cancelledDeferred
192
+
193
+ ```ts
194
+ cancelledDeferred: NonNullable < AssistantMessage["deferred"] > [];
195
+ ```
196
+
197
+ ---
198
+
199
+ ### FauxResponseFactory
200
+
201
+ ```ts
202
+ type FauxResponseFactory = (
203
+ context,
204
+ options,
205
+ state,
206
+ model,
207
+ ) => AssistantMessage | Promise<AssistantMessage>;
208
+ ```
209
+
210
+ Function that observes a model request and supplies a scripted reply.
211
+
212
+ #### Parameters
213
+
214
+ | Parameter | Type |
215
+ | --------- | -------------------------------------------------------------------------- |
216
+ | `context` | [`Context`](effect.md#context) |
217
+ | `options` | `Parameters`\<[`MuleStreamFunction`](index.md#mulestreamfunction)\>\[`2`\] |
218
+ | `state` | [`FauxProviderState`](#fauxproviderstate) |
219
+ | `model` | [`Model`](effect.md#model-1)\<[`Api`](effect.md#api)\> |
220
+
221
+ #### Returns
222
+
223
+ \| [`AssistantMessage`](effect.md#assistantmessage) \|
224
+ `Promise`\<[`AssistantMessage`](effect.md#assistantmessage)\>
225
+
226
+ ---
227
+
228
+ ### FauxResponseStep
229
+
230
+ ```ts
231
+ type FauxResponseStep = AssistantMessage | FauxResponseFactory;
232
+ ```
233
+
234
+ A scripted reply or a factory that observes the normalized request.
235
+
236
+ ---
237
+
13
238
  ### FauxModel
14
239
 
15
240
  ```ts
16
241
  type FauxModel = Readonly<{
17
242
  model: Model<Api>;
18
- stream: FauxProviderHandle["provider"]["streamSimple"];
243
+ stream: (...args) => AssistantMessageEventStream;
19
244
  retryable: (message) => boolean;
20
245
  setResponses: (replies) => void;
21
- state: FauxProviderHandle["state"];
246
+ state: FauxProviderState;
247
+ getPendingResponseCount: () => number;
22
248
  }>;
23
249
  ```
24
250
 
@@ -36,10 +262,10 @@ Create a credential-free model for tests and runnable examples.
36
262
 
37
263
  #### Parameters
38
264
 
39
- | Parameter | Type |
40
- | --------- | ----------------------------- |
41
- | `replies` | readonly `FauxResponseStep`[] |
42
- | `options` | `RegisterFauxProviderOptions` |
265
+ | Parameter | Type |
266
+ | --------- | ------------------------------------------------------------- |
267
+ | `replies` | readonly [`FauxResponseStep`](#fauxresponsestep)[] |
268
+ | `options` | [`RegisterFauxProviderOptions`](#registerfauxprovideroptions) |
43
269
 
44
270
  #### Returns
45
271
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/mule",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Effect-native Pi model and tool loop",
6
6
  "type": "module",