modelpact 2.0.2

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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +372 -0
  3. package/dist/helpers/abort.d.ts +14 -0
  4. package/dist/helpers/abort.d.ts.map +1 -0
  5. package/dist/helpers/abort.js +22 -0
  6. package/dist/helpers/abort.js.map +1 -0
  7. package/dist/helpers/lifetime.d.ts +34 -0
  8. package/dist/helpers/lifetime.d.ts.map +1 -0
  9. package/dist/helpers/lifetime.js +71 -0
  10. package/dist/helpers/lifetime.js.map +1 -0
  11. package/dist/helpers/monitor.d.ts +52 -0
  12. package/dist/helpers/monitor.d.ts.map +1 -0
  13. package/dist/helpers/monitor.js +69 -0
  14. package/dist/helpers/monitor.js.map +1 -0
  15. package/dist/helpers/ndjson.d.ts +19 -0
  16. package/dist/helpers/ndjson.d.ts.map +1 -0
  17. package/dist/helpers/ndjson.js +39 -0
  18. package/dist/helpers/ndjson.js.map +1 -0
  19. package/dist/helpers/overflow.d.ts +50 -0
  20. package/dist/helpers/overflow.d.ts.map +1 -0
  21. package/dist/helpers/overflow.js +72 -0
  22. package/dist/helpers/overflow.js.map +1 -0
  23. package/dist/helpers/transcript.d.ts +22 -0
  24. package/dist/helpers/transcript.d.ts.map +1 -0
  25. package/dist/helpers/transcript.js +26 -0
  26. package/dist/helpers/transcript.js.map +1 -0
  27. package/dist/index.d.ts +23 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +19 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/lifecycle/01_access.d.ts +13 -0
  32. package/dist/lifecycle/01_access.d.ts.map +1 -0
  33. package/dist/lifecycle/01_access.js +45 -0
  34. package/dist/lifecycle/01_access.js.map +1 -0
  35. package/dist/lifecycle/02_download.d.ts +8 -0
  36. package/dist/lifecycle/02_download.d.ts.map +1 -0
  37. package/dist/lifecycle/02_download.js +12 -0
  38. package/dist/lifecycle/02_download.js.map +1 -0
  39. package/dist/lifecycle/03_open.d.ts +22 -0
  40. package/dist/lifecycle/03_open.d.ts.map +1 -0
  41. package/dist/lifecycle/03_open.js +39 -0
  42. package/dist/lifecycle/03_open.js.map +1 -0
  43. package/dist/lifecycle/04_generate.d.ts +15 -0
  44. package/dist/lifecycle/04_generate.d.ts.map +1 -0
  45. package/dist/lifecycle/04_generate.js +154 -0
  46. package/dist/lifecycle/04_generate.js.map +1 -0
  47. package/dist/lifecycle/05_close.d.ts +4 -0
  48. package/dist/lifecycle/05_close.d.ts.map +1 -0
  49. package/dist/lifecycle/05_close.js +8 -0
  50. package/dist/lifecycle/05_close.js.map +1 -0
  51. package/dist/providers/create.d.ts +5 -0
  52. package/dist/providers/create.d.ts.map +1 -0
  53. package/dist/providers/create.js +7 -0
  54. package/dist/providers/create.js.map +1 -0
  55. package/dist/providers/mock.d.ts +36 -0
  56. package/dist/providers/mock.d.ts.map +1 -0
  57. package/dist/providers/mock.js +128 -0
  58. package/dist/providers/mock.js.map +1 -0
  59. package/dist/providers/ollama.d.ts +33 -0
  60. package/dist/providers/ollama.d.ts.map +1 -0
  61. package/dist/providers/ollama.js +275 -0
  62. package/dist/providers/ollama.js.map +1 -0
  63. package/dist/providers/prompt-api.d.ts +23 -0
  64. package/dist/providers/prompt-api.d.ts.map +1 -0
  65. package/dist/providers/prompt-api.js +203 -0
  66. package/dist/providers/prompt-api.js.map +1 -0
  67. package/dist/providers/registry.d.ts +22 -0
  68. package/dist/providers/registry.d.ts.map +1 -0
  69. package/dist/providers/registry.js +30 -0
  70. package/dist/providers/registry.js.map +1 -0
  71. package/dist/testing/contract.d.ts +47 -0
  72. package/dist/testing/contract.d.ts.map +1 -0
  73. package/dist/testing/contract.js +518 -0
  74. package/dist/testing/contract.js.map +1 -0
  75. package/dist/testing/index.d.ts +9 -0
  76. package/dist/testing/index.d.ts.map +1 -0
  77. package/dist/testing/index.js +9 -0
  78. package/dist/testing/index.js.map +1 -0
  79. package/dist/types/backend.d.ts +63 -0
  80. package/dist/types/backend.d.ts.map +1 -0
  81. package/dist/types/backend.js +11 -0
  82. package/dist/types/backend.js.map +1 -0
  83. package/dist/types/failures.d.ts +115 -0
  84. package/dist/types/failures.d.ts.map +1 -0
  85. package/dist/types/failures.js +68 -0
  86. package/dist/types/failures.js.map +1 -0
  87. package/dist/types/foundations.d.ts +35 -0
  88. package/dist/types/foundations.d.ts.map +1 -0
  89. package/dist/types/foundations.js +30 -0
  90. package/dist/types/foundations.js.map +1 -0
  91. package/dist/types/messages.d.ts +30 -0
  92. package/dist/types/messages.d.ts.map +1 -0
  93. package/dist/types/messages.js +2 -0
  94. package/dist/types/messages.js.map +1 -0
  95. package/dist/types/provider.d.ts +22 -0
  96. package/dist/types/provider.d.ts.map +1 -0
  97. package/dist/types/provider.js +2 -0
  98. package/dist/types/provider.js.map +1 -0
  99. package/dist/types/session.d.ts +156 -0
  100. package/dist/types/session.d.ts.map +1 -0
  101. package/dist/types/session.js +2 -0
  102. package/dist/types/session.js.map +1 -0
  103. package/dist/types/usage.d.ts +25 -0
  104. package/dist/types/usage.d.ts.map +1 -0
  105. package/dist/types/usage.js +16 -0
  106. package/dist/types/usage.js.map +1 -0
  107. package/package.json +85 -0
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Stage four, once per turn: refuse at the door, hold the session, guard the
3
+ * stream, record the turn, free the session.
4
+ *
5
+ * `prompt` is `promptStream` drained, unless the backend has a whole-answer
6
+ * call. Either way a turn cannot leave the session held: every exit from the
7
+ * guarded stream — done, error, abort, reader cancel — ends it.
8
+ */
9
+ import { abortFailure } from "../helpers/abort.js";
10
+ import { err, ok } from "../types/foundations.js";
11
+ import { AiError, failureFromError, } from "../types/failures.js";
12
+ /**
13
+ * The one place a turn counts: the record and the meter move together, so a
14
+ * turn that reached here is in both and one that did not is in neither.
15
+ */
16
+ const completeTurn = (state, input, answer) => {
17
+ state.transcript.append(input, answer);
18
+ const usage = state.model.usage();
19
+ state.events.report(usage);
20
+ };
21
+ const toGenerateRequest = (state, signal, options) => {
22
+ const history = state.transcript.entries();
23
+ return options?.schema === undefined
24
+ ? { signal, history }
25
+ : { signal, history, schema: options.schema };
26
+ };
27
+ const toFailure = (error) => error instanceof AiError ? error.failure : failureFromError(error);
28
+ const toAiError = (error) => error instanceof AiError ? error : new AiError(failureFromError(error));
29
+ /** Every refusal a generating call owes is `begin`'s to make; past it, the session is held. */
30
+ const startTurn = (state, callName, options) => {
31
+ const turnResult = state.lifetime.begin(callName, options?.signal);
32
+ if (!turnResult.ok)
33
+ return turnResult;
34
+ const turn = turnResult.value;
35
+ const request = toGenerateRequest(state, turn.signal, options);
36
+ return ok({ turn, request });
37
+ };
38
+ /** `cancel` on a source that already errored rejects, and there is nothing to do about that. */
39
+ const releaseReader = (reader) => {
40
+ reader.cancel().catch(() => undefined);
41
+ };
42
+ /**
43
+ * The backend's stream under the lifecycle's rules. An abort errors it with an
44
+ * `AiError` — a reader has nowhere to put a Result — and so does anything the
45
+ * source throws, mapped through `failureFromError`.
46
+ */
47
+ const guardStream = (sourceStream, signal, hooks) => {
48
+ const reader = sourceStream.getReader();
49
+ const answerParts = [];
50
+ return new ReadableStream({
51
+ pull: async (controller) => {
52
+ try {
53
+ const chunk = await reader.read();
54
+ if (signal.aborted)
55
+ throw new AiError(abortFailure(signal));
56
+ if (chunk.done) {
57
+ hooks.finish(answerParts.join(""));
58
+ controller.close();
59
+ return;
60
+ }
61
+ answerParts.push(chunk.value);
62
+ controller.enqueue(chunk.value);
63
+ }
64
+ catch (error) {
65
+ hooks.abandon();
66
+ releaseReader(reader);
67
+ throw toAiError(error);
68
+ }
69
+ },
70
+ cancel: (reason) => {
71
+ hooks.abandon();
72
+ return reader.cancel(reason);
73
+ },
74
+ });
75
+ };
76
+ const callGenerate = async (model, input, request) => {
77
+ try {
78
+ return await model.generateStream(input, request);
79
+ }
80
+ catch (error) {
81
+ return err(toFailure(error));
82
+ }
83
+ };
84
+ const startStream = async (state, callName, input, options) => {
85
+ const startedTurnResult = startTurn(state, callName, options);
86
+ if (!startedTurnResult.ok)
87
+ return startedTurnResult;
88
+ const { turn, request } = startedTurnResult.value;
89
+ const streamResult = await callGenerate(state.model, input, request);
90
+ if (!streamResult.ok) {
91
+ state.lifetime.end(turn);
92
+ return streamResult;
93
+ }
94
+ // The token travels into the hooks, so a stream abandoned long ago cannot
95
+ // end the turn running when its `cancel` finally arrives.
96
+ const guardedStream = guardStream(streamResult.value, turn.signal, {
97
+ finish: (answer) => {
98
+ completeTurn(state, input, answer);
99
+ state.lifetime.end(turn);
100
+ },
101
+ abandon: () => {
102
+ state.lifetime.end(turn);
103
+ },
104
+ });
105
+ return ok(guardedStream);
106
+ };
107
+ const drainStream = async (stream) => {
108
+ const reader = stream.getReader();
109
+ const answerParts = [];
110
+ try {
111
+ for (;;) {
112
+ const chunk = await reader.read();
113
+ if (chunk.done)
114
+ return ok(answerParts.join(""));
115
+ answerParts.push(chunk.value);
116
+ }
117
+ }
118
+ catch (error) {
119
+ return err(toFailure(error));
120
+ }
121
+ };
122
+ const promptWhole = async (state, generateWhole, input, options) => {
123
+ const startedTurnResult = startTurn(state, "prompt", options);
124
+ if (!startedTurnResult.ok)
125
+ return startedTurnResult;
126
+ const { turn, request } = startedTurnResult.value;
127
+ try {
128
+ const answerResult = await generateWhole(input, request);
129
+ if (!answerResult.ok)
130
+ return answerResult;
131
+ if (turn.signal.aborted)
132
+ return err(abortFailure(turn.signal));
133
+ completeTurn(state, input, answerResult.value);
134
+ return answerResult;
135
+ }
136
+ catch (error) {
137
+ return err(toFailure(error));
138
+ }
139
+ finally {
140
+ state.lifetime.end(turn);
141
+ }
142
+ };
143
+ export const prompt = async (state, input, options) => {
144
+ const generateWhole = state.model.generateWhole;
145
+ if (generateWhole !== undefined)
146
+ return promptWhole(state, generateWhole, input, options);
147
+ const streamResult = await startStream(state, "prompt", input, options);
148
+ if (!streamResult.ok)
149
+ return streamResult;
150
+ const answerResult = await drainStream(streamResult.value);
151
+ return answerResult;
152
+ };
153
+ export const promptStream = (state, input, options) => startStream(state, "promptStream", input, options);
154
+ //# sourceMappingURL=04_generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"04_generate.js","sourceRoot":"","sources":["../../src/lifecycle/04_generate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EACL,OAAO,EACP,gBAAgB,GAEjB,MAAM,sBAAsB,CAAC;AAiB9B;;;GAGG;AACH,MAAM,YAAY,GAAG,CACnB,KAAmB,EACnB,KAAa,EACb,MAAc,EACR,EAAE;IACR,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAClC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CACxB,KAAmB,EACnB,MAAmB,EACnB,OAAyB,EACR,EAAE;IACnB,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;IAC3C,OAAO,OAAO,EAAE,MAAM,KAAK,SAAS;QAClC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE;QACrB,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,KAAc,EAAa,EAAE,CAC9C,KAAK,YAAY,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAErE,MAAM,SAAS,GAAG,CAAC,KAAc,EAAW,EAAE,CAC5C,KAAK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M,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACxE,IAAI,CAAC,YAAY,CAAC,EAAE;QAAE,OAAO,YAAY,CAAC;IAC1C,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAC3D,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,KAAmB,EACnB,KAAa,EACb,OAAyB,EAC2B,EAAE,CACtD,WAAW,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ /** Stage five: the closed phase ends the call in flight and refuses the later ones; the model is released on the one close that does it. */
2
+ import type { SessionState } from "./03_open.js";
3
+ export declare const closeSession: (state: SessionState) => void;
4
+ //# sourceMappingURL=05_close.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"05_close.d.ts","sourceRoot":"","sources":["../../src/lifecycle/05_close.ts"],"names":[],"mappings":"AAAA,4IAA4I;AAE5I,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,eAAO,MAAM,YAAY,GAAI,OAAO,YAAY,KAAG,IAIlD,CAAC"}
@@ -0,0 +1,8 @@
1
+ /** Stage five: the closed phase ends the call in flight and refuses the later ones; the model is released on the one close that does it. */
2
+ export const closeSession = (state) => {
3
+ const closeOutcome = state.lifetime.close();
4
+ if (closeOutcome === "already-closed")
5
+ return;
6
+ state.model.dispose();
7
+ };
8
+ //# sourceMappingURL=05_close.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"05_close.js","sourceRoot":"","sources":["../../src/lifecycle/05_close.ts"],"names":[],"mappings":"AAAA,4IAA4I;AAI5I,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAmB,EAAQ,EAAE;IACxD,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC5C,IAAI,YAAY,KAAK,gBAAgB;QAAE,OAAO;IAC9C,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;AACxB,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** The entry: a backend behind the lifecycle is an `AiProvider`. */
2
+ import type { ModelBackend } from "../types/backend.js";
3
+ import type { AiProvider } from "../types/provider.js";
4
+ export declare const createProvider: (backend: ModelBackend) => AiProvider;
5
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/providers/create.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAGpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,eAAO,MAAM,cAAc,GAAI,SAAS,YAAY,KAAG,UAGrD,CAAC"}
@@ -0,0 +1,7 @@
1
+ /** The entry: a backend behind the lifecycle is an `AiProvider`. */
2
+ import { checkAccess } from "../lifecycle/01_access.js";
3
+ export const createProvider = (backend) => ({
4
+ name: backend.name,
5
+ access: (request) => checkAccess(backend, request),
6
+ });
7
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/providers/create.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAIxD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAqB,EAAc,EAAE,CAAC,CAAC;IACpE,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC;CACnD,CAAC,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * A backend with nothing behind it: no daemon, no browser, no network.
3
+ *
4
+ * It exists to hold the contract still. `../lifecycle` supplies every
5
+ * guarantee in `../types`, this file supplies only the model — words in,
6
+ * words out, a download that never happens — and `../testing/contract.js`
7
+ * runs against the pair on every commit. A backend that cannot be reached from
8
+ * a test runner is checked against the same assertions this one passes.
9
+ */
10
+ import type { AiProvider } from "../types/provider.js";
11
+ export interface MockConfig {
12
+ /**
13
+ * Narrow it and one ordinary turn overflows, which is the only way to reach
14
+ * the `contextoverflow` path without generating for minutes.
15
+ */
16
+ readonly contextWindow?: number;
17
+ /**
18
+ * The answer, already cut into deltas. More than one, or a caller cannot
19
+ * tell a stream from a single write.
20
+ */
21
+ readonly reply?: (input: string) => readonly string[];
22
+ /**
23
+ * What to answer when a caller sends a schema. Absent, the provider refuses
24
+ * such a call — the contract allows honouring or refusing, never ignoring,
25
+ * and a mock that answered prose would be the ignoring case.
26
+ */
27
+ readonly schemaReply?: string;
28
+ /** Which branch `access` takes; `ready` unless said otherwise. */
29
+ readonly access?: "ready" | "unavailable" | "needs-download";
30
+ /** Progress to report before opening on the `needs-download` branch. */
31
+ readonly downloadSteps?: readonly number[];
32
+ /** Milliseconds per delta, and per download step. Zero would make "while the first runs" untestable. */
33
+ readonly delayMs?: number;
34
+ }
35
+ export declare function makeMockProvider(config?: MockConfig): AiProvider;
36
+ //# sourceMappingURL=mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../src/providers/mock.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAmBH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAKvD,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,MAAM,EAAE,CAAC;IACtD;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,kEAAkE;IAClE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,aAAa,GAAG,gBAAgB,CAAC;IAC7D,wEAAwE;IACxE,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,wGAAwG;IACxG,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAyID,wBAAgB,gBAAgB,CAAC,MAAM,GAAE,UAAe,GAAG,UAAU,CAQpE"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * A backend with nothing behind it: no daemon, no browser, no network.
3
+ *
4
+ * It exists to hold the contract still. `../lifecycle` supplies every
5
+ * guarantee in `../types`, this file supplies only the model — words in,
6
+ * words out, a download that never happens — and `../testing/contract.js`
7
+ * runs against the pair on every commit. A backend that cannot be reached from
8
+ * a test runner is checked against the same assertions this one passes.
9
+ */
10
+ import { err, fraction, ok, tokens, } from "../types/foundations.js";
11
+ import { contextUsage } from "../types/usage.js";
12
+ import { createProvider } from "./create.js";
13
+ const DEFAULTS = {
14
+ contextWindow: 4096,
15
+ reply: (input) => {
16
+ const preview = input.slice(0, 40);
17
+ const sentence = `Answering «${preview}». `;
18
+ const words = sentence.match(/\S+\s*/g);
19
+ return words ?? ["Answer."];
20
+ },
21
+ downloadSteps: [0, 0.5, 1],
22
+ delayMs: 1,
23
+ };
24
+ const NO_SCHEMA_REPLY = {
25
+ kind: "failed",
26
+ detail: "no schemaReply configured",
27
+ };
28
+ const ZERO_TOKENS = tokens(0);
29
+ /** Words in, words out: a count that grows the way a real one does, without pretending to be a tokenizer. */
30
+ const countTokens = (text) => {
31
+ const pieces = text.split(/\s+/);
32
+ const words = pieces.filter(Boolean);
33
+ return words.length;
34
+ };
35
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
36
+ class MockModel {
37
+ #contextWindow;
38
+ #reply;
39
+ #schemaReply;
40
+ #delayMs;
41
+ #usedTokens = 0;
42
+ constructor(config, history) {
43
+ this.#contextWindow = config.contextWindow ?? DEFAULTS.contextWindow;
44
+ this.#reply = config.reply ?? DEFAULTS.reply;
45
+ this.#schemaReply = config.schemaReply;
46
+ this.#delayMs = config.delayMs ?? DEFAULTS.delayMs;
47
+ // Charged at open, as a real backend charges a transcript it was handed.
48
+ for (const message of history ?? []) {
49
+ this.#usedTokens += countTokens(message.content);
50
+ }
51
+ }
52
+ generateStream = (input, request) => {
53
+ const replyParts = this.#chooseReply(input, request.schema);
54
+ if (replyParts === null)
55
+ return Promise.resolve(err(NO_SCHEMA_REPLY));
56
+ const stream = this.#streamReply(input, replyParts);
57
+ return Promise.resolve(ok(stream));
58
+ };
59
+ usage = () => {
60
+ const used = tokens(this.#usedTokens) ?? ZERO_TOKENS;
61
+ return contextUsage(used, this.#contextWindow);
62
+ };
63
+ dispose = () => undefined;
64
+ /** Null is the refusal: a schema with no reply configured for it. */
65
+ #chooseReply(input, schema) {
66
+ if (schema === undefined)
67
+ return this.#reply(input);
68
+ if (this.#schemaReply === undefined)
69
+ return null;
70
+ return [this.#schemaReply];
71
+ }
72
+ /** One delta per pull, `delayMs` apart: the pace is what makes "while the first one runs" a reachable state. */
73
+ #streamReply(input, replyParts) {
74
+ let index = 0;
75
+ return new ReadableStream({
76
+ pull: async (controller) => {
77
+ await sleep(this.#delayMs);
78
+ const part = replyParts[index];
79
+ if (part === undefined) {
80
+ this.#charge(input, replyParts.join(""));
81
+ controller.close();
82
+ return;
83
+ }
84
+ index += 1;
85
+ controller.enqueue(part);
86
+ },
87
+ });
88
+ }
89
+ #charge(input, answer) {
90
+ this.#usedTokens += countTokens(input) + countTokens(answer);
91
+ }
92
+ }
93
+ const getAvailability = (config) => {
94
+ if (config.access === "unavailable") {
95
+ return { kind: "unavailable", reason: { kind: "unsupported" } };
96
+ }
97
+ if (config.access === "needs-download") {
98
+ return { kind: "needs-download", started: false };
99
+ }
100
+ return { kind: "ready" };
101
+ };
102
+ const reportDownload = async (steps, delayMs, reportProgress) => {
103
+ for (const step of steps) {
104
+ await sleep(delayMs);
105
+ const progress = fraction(step);
106
+ if (progress !== null)
107
+ reportProgress(progress);
108
+ }
109
+ };
110
+ const connectMock = async (config, options) => {
111
+ if (config.access === "needs-download") {
112
+ const steps = config.downloadSteps ?? DEFAULTS.downloadSteps;
113
+ const delayMs = config.delayMs ?? DEFAULTS.delayMs;
114
+ await reportDownload(steps, delayMs, options.reportProgress);
115
+ }
116
+ const model = new MockModel(config, options.session.history);
117
+ return ok(model);
118
+ };
119
+ export function makeMockProvider(config = {}) {
120
+ const backend = {
121
+ name: "mock",
122
+ modalities: ["text"],
123
+ availability: () => getAvailability(config),
124
+ connect: (options) => connectMock(config, options),
125
+ };
126
+ return createProvider(backend);
127
+ }
128
+ //# sourceMappingURL=mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.js","sourceRoot":"","sources":["../../src/providers/mock.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,OAAO,EACL,GAAG,EACH,QAAQ,EACR,EAAE,EACF,MAAM,GAIP,MAAM,yBAAyB,CAAC;AAIjC,OAAO,EAAE,YAAY,EAAqB,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AA2B7C,MAAM,QAAQ,GAAG;IACf,aAAa,EAAE,IAAI;IACnB,KAAK,EAAE,CAAC,KAAa,EAAqB,EAAE;QAC1C,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACnC,MAAM,QAAQ,GAAG,cAAc,OAAO,KAAK,CAAC;QAC5C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACxC,OAAO,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC;IAC9B,CAAC;IACD,aAAa,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAsB;IAC/C,OAAO,EAAE,CAAC;CACX,CAAC;AAEF,MAAM,eAAe,G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M,KAAK,GAAG,MAAM,CAAC,aAAa,IAAI,QAAQ,CAAC,aAAa,CAAC;QAC7D,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC;QACnD,MAAM,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IAC/D,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7D,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,UAAU,gBAAgB,CAAC,SAAqB,EAAE;IACtD,MAAM,OAAO,GAAiB;QAC5B,IAAI,EAAE,MAAM;QACZ,UAAU,EAAE,CAAC,MAAM,CAAC;QACpB,YAAY,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC;QAC3C,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC;KACnD,CAAC;IACF,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Ollama on a machine you can reach over HTTP.
3
+ *
4
+ * The daemon keeps nothing between requests: `/api/chat` is handed the whole
5
+ * conversation every time, which is what `request.history` is for. Three
6
+ * endpoints are the whole backend — `/api/tags` says what is downloaded,
7
+ * `/api/pull` downloads, `/api/chat` generates — and everything else the
8
+ * contract promises is `../lifecycle`'s.
9
+ *
10
+ * Shapes here were read off a running daemon, not off the docs: a chat stream
11
+ * is NDJSON whose last line carries the counts, a pull line carries `completed`
12
+ * and `total` per layer, and an error is an HTTP status with `{"error": "…"}`.
13
+ */
14
+ import type { AiProvider } from "../types/provider.js";
15
+ export interface OllamaConfig {
16
+ /** The tag as `/api/tags` lists it, such as `granite4:350m`. */
17
+ readonly model: string;
18
+ /**
19
+ * `127.0.0.1` and not `localhost`: the daemon binds the one, and the name
20
+ * can resolve to the other family first and refuse the connection.
21
+ */
22
+ readonly host?: string;
23
+ /**
24
+ * Sent as `num_ctx`, and therefore the window in force rather than a guess
25
+ * at one. The default matches the daemon's own; a model that can take more
26
+ * will, at the price of the memory the cache for it costs.
27
+ */
28
+ readonly contextWindow?: number;
29
+ /** For a proxy, an auth header, or a test with no daemon behind it. */
30
+ readonly fetch?: typeof globalThis.fetch;
31
+ }
32
+ export declare function makeOllamaProvider(config: OllamaConfig): AiProvider;
33
+ //# sourceMappingURL=ollama.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama.d.ts","sourceRoot":"","sources":["../../src/providers/ollama.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAoBH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIvD,MAAM,WAAW,YAAY;IAC3B,gEAAgE;IAChE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,uEAAuE;IACvE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CAC1C;AA+TD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAQnE"}