narrarium-engine 0.1.5 → 0.1.7
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/README.md +90 -12
- package/dist/ai/config.d.ts +22 -0
- package/dist/ai/config.d.ts.map +1 -1
- package/dist/ai/config.js +19 -0
- package/dist/ai/config.js.map +1 -1
- package/dist/ai/deadlines.d.ts +79 -0
- package/dist/ai/deadlines.d.ts.map +1 -0
- package/dist/ai/deadlines.js +151 -0
- package/dist/ai/deadlines.js.map +1 -0
- package/dist/ai/fetch-client.d.ts +41 -5
- package/dist/ai/fetch-client.d.ts.map +1 -1
- package/dist/ai/fetch-client.js +374 -126
- package/dist/ai/fetch-client.js.map +1 -1
- package/dist/ai/request.d.ts +8 -1
- package/dist/ai/request.d.ts.map +1 -1
- package/dist/ai/request.js +18 -1
- package/dist/ai/request.js.map +1 -1
- package/dist/ai/types.d.ts +47 -1
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/ai/types.js +2 -0
- package/dist/ai/types.js.map +1 -1
- package/dist/autopilot/errors.d.ts +32 -0
- package/dist/autopilot/errors.d.ts.map +1 -0
- package/dist/autopilot/errors.js +190 -0
- package/dist/autopilot/errors.js.map +1 -0
- package/dist/autopilot/runner.d.ts +12 -3
- package/dist/autopilot/runner.d.ts.map +1 -1
- package/dist/autopilot/runner.js +60 -26
- package/dist/autopilot/runner.js.map +1 -1
- package/dist/autopilot/session.d.ts +1 -1
- package/dist/autopilot/session.d.ts.map +1 -1
- package/dist/autopilot/session.js +16 -7
- package/dist/autopilot/session.js.map +1 -1
- package/dist/autopilot/state.d.ts +35 -2
- package/dist/autopilot/state.d.ts.map +1 -1
- package/dist/autopilot/state.js +117 -4
- package/dist/autopilot/state.js.map +1 -1
- package/dist/autopilot/tasks.d.ts.map +1 -1
- package/dist/autopilot/tasks.js +11 -2
- package/dist/autopilot/tasks.js.map +1 -1
- package/dist/autopilot/types.d.ts +112 -8
- package/dist/autopilot/types.d.ts.map +1 -1
- package/dist/autopilot/types.js +1 -0
- package/dist/autopilot/types.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/server/client.d.ts +9 -0
- package/dist/server/client.d.ts.map +1 -1
- package/dist/server/client.js +15 -0
- package/dist/server/client.js.map +1 -1
- package/dist/server/protocol.d.ts +19 -0
- package/dist/server/protocol.d.ts.map +1 -1
- package/dist/server/protocol.js +11 -0
- package/dist/server/protocol.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
import type { AiPricingConfig, AiRuntimeConfig } from "./config.js";
|
|
2
|
-
import { type AiPort, type AiUsage } from "./types.js";
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { AiPricingConfig, AiRuntimeConfig, AiStreamMode } from "./config.js";
|
|
2
|
+
import { type AiPort, type AiTimeoutPhase, type AiUsage } from "./types.js";
|
|
3
|
+
export { DEFAULT_REQUEST_TIMEOUT_MS, MIN_REQUEST_TIMEOUT_MS, TOTAL_REQUEST_CAP_MS } from "./deadlines.js";
|
|
4
|
+
/**
|
|
5
|
+
* Raw bytes of a stream include the JSON envelope of every piece (a few hundred bytes for a few characters), so a long reasoning phase is
|
|
6
|
+
* far larger than its text. A stream over this many bytes is a model that loops, and is stopped.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MAX_STREAM_TRANSPORT_BYTES = 256000000;
|
|
9
|
+
/** The characters of reasoning a stream may carry before it is taken for a loop and stopped. */
|
|
10
|
+
export declare const MAX_STREAM_REASONING_CHARACTERS = 16000000;
|
|
5
11
|
export interface FetchAiMessage {
|
|
6
12
|
role: "system" | "user";
|
|
7
13
|
content: string;
|
|
8
14
|
}
|
|
15
|
+
/** The three deadlines of an attempt, in milliseconds, as they are applied (the routing time that is left included). */
|
|
16
|
+
export interface FetchAiTimeouts {
|
|
17
|
+
/** How long the provider has to begin answering: the connection and the headers. For a request that does not stream it is the whole call. */
|
|
18
|
+
startMs: number;
|
|
19
|
+
/** The longest silence between two pieces of a stream (it applies to streamed replies only). */
|
|
20
|
+
idleMs: number;
|
|
21
|
+
/** The most the attempt may take, whatever the provider keeps sending. */
|
|
22
|
+
capMs: number;
|
|
23
|
+
/** The provider timeout the integration asked for, when the minimum raised it to `startMs`. */
|
|
24
|
+
raised?: {
|
|
25
|
+
from: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
9
28
|
export interface FetchAiAttempt {
|
|
10
29
|
label: string;
|
|
11
30
|
capability: string;
|
|
@@ -25,8 +44,12 @@ export interface FetchAiAttempt {
|
|
|
25
44
|
tools: boolean;
|
|
26
45
|
/** The origin and path every request of this integration starts with (never a key). */
|
|
27
46
|
endpoint: string | null;
|
|
28
|
-
/** How long
|
|
47
|
+
/** How long the provider has to begin answering (`timeouts.startMs`). */
|
|
29
48
|
timeoutMs: number;
|
|
49
|
+
/** The three deadlines of this attempt. */
|
|
50
|
+
timeouts: FetchAiTimeouts;
|
|
51
|
+
/** What the integration says about streaming (`auto` unless it says `off`). */
|
|
52
|
+
streamMode: AiStreamMode;
|
|
30
53
|
}
|
|
31
54
|
export interface FetchAiAttemptEnd {
|
|
32
55
|
attemptId: string;
|
|
@@ -55,6 +78,14 @@ export interface FetchAiAttemptEnd {
|
|
|
55
78
|
retryAfterMs?: number;
|
|
56
79
|
/** The limit that ran out, for a timeout. */
|
|
57
80
|
timeoutMs?: number;
|
|
81
|
+
/** Which deadline ran out, for a timeout. */
|
|
82
|
+
timeoutPhase?: AiTimeoutPhase;
|
|
83
|
+
/** The reply was read as a stream of events (and not as one JSON body). */
|
|
84
|
+
streamed: boolean;
|
|
85
|
+
/** Milliseconds from the start of the attempt to the first byte of the reply: of its body for a stream, of the response for a JSON body. Absent when nothing arrived. */
|
|
86
|
+
firstByteMs?: number;
|
|
87
|
+
/** For a structured request: whether the model delivered the result as a function call. Absent for any other request and when nothing arrived. */
|
|
88
|
+
toolCalled?: boolean;
|
|
58
89
|
durationMs: number;
|
|
59
90
|
}
|
|
60
91
|
/** One side of a fallback that crosses a privacy boundary. */
|
|
@@ -76,6 +107,11 @@ export interface FetchAiOptions {
|
|
|
76
107
|
githubModelsBaseUrl?: string;
|
|
77
108
|
/** Used when an integration has no request timeout (default `DEFAULT_REQUEST_TIMEOUT_MS`). */
|
|
78
109
|
defaultTimeoutMs?: number;
|
|
110
|
+
/**
|
|
111
|
+
* The shortest start or idle deadline an attempt is given (default `MIN_REQUEST_TIMEOUT_MS`, 30 s). It exists for tests that count in
|
|
112
|
+
* milliseconds: a host has no reason to lower it.
|
|
113
|
+
*/
|
|
114
|
+
minimumTimeoutMs?: number;
|
|
79
115
|
/** An attempt is about to be sent. Never breaks the call. */
|
|
80
116
|
onAttempt?: (attempt: FetchAiAttempt) => void;
|
|
81
117
|
/** An attempt ended, whether it worked or not: for costs and debug panels. Never breaks the call. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-client.d.ts","sourceRoot":"","sources":["../../src/ai/fetch-client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch-client.d.ts","sourceRoot":"","sources":["../../src/ai/fetch-client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAOlF,OAAO,EAAiE,KAAK,MAAM,EAAgE,KAAK,cAAc,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAGzM,OAAO,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE1G;;;GAGG;AACH,eAAO,MAAM,0BAA0B,YAAc,CAAC;AACtD,gGAAgG;AAChG,eAAO,MAAM,+BAA+B,WAAa,CAAC;AAK1D,MAAM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