@arcforge/types 2.0.219 → 2.0.244
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/package.json +6 -2
- package/src/agent-handle.ts +2 -1
- package/src/blueprint.ts +19 -3
- package/src/body/body.ts +669 -0
- package/src/cognet/blueprint.ts +32 -4
- package/src/cognet/cognet.ts +126 -11
- package/src/cognet/index.ts +2 -2
- package/src/config.ts +21 -3
- package/src/connections.ts +70 -0
- package/src/define.ts +34 -0
- package/src/engine.ts +33 -3
- package/src/error.ts +11 -0
- package/src/handle.ts +67 -0
- package/src/index.ts +8 -0
- package/src/inference.ts +193 -12
- package/src/kernel/abi.ts +132 -10
- package/src/kernel/index.ts +1 -1
- package/src/machine.ts +17 -0
- package/src/provider-usage.ts +63 -0
- package/src/services.ts +79 -0
- package/src/session/channel.ts +15 -0
- package/src/session/envelope.ts +10 -1
- package/src/session/events/activity.ts +13 -1
- package/src/session/events/build.ts +26 -1
- package/src/session/events/cognet.ts +211 -15
- package/src/session/events/kernel.ts +20 -0
- package/src/session/events/runtime.ts +29 -1
- package/src/session/events/stdio/output.ts +6 -0
- package/src/session/events/stdio/shared.ts +35 -0
- package/src/session/events/stdio/stimuli.ts +17 -0
- package/src/session/index.ts +4 -1
- package/src/session/session.ts +2 -2
- package/src/session/text.ts +36 -0
- package/src/supervisor.ts +45 -4
- package/src/tui-contract.ts +1 -1
- package/src/tui.ts +14 -0
- package/src/usage.ts +83 -0
- package/src/world/world.ts +224 -0
package/src/cognet/blueprint.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AxonEntryEvent } from "../session/events/entries"
|
|
2
|
-
import type { CognetDefinition, CognetStimulusSupport } from "./cognet"
|
|
2
|
+
import type { CognetDefinition, CognetSchedule, CognetStimulusSupport, CognetUse } from "./cognet"
|
|
3
3
|
import type { EngineRequirements, ResolvedEngineFacts } from "../inference"
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -18,7 +18,25 @@ import type { EngineRequirements, ResolvedEngineFacts } from "../inference"
|
|
|
18
18
|
* policy, and pre-load checks; the loaded definition is the authority and
|
|
19
19
|
* a disagreement fails loudly.
|
|
20
20
|
*/
|
|
21
|
-
export type CognetBlueprint = {
|
|
21
|
+
export type CognetBlueprint = CognetSlot & CognetCarrier & {
|
|
22
|
+
/**
|
|
23
|
+
* How the brain wakes, from the definition itself. Carried so a client can
|
|
24
|
+
* tell, before anything loads, whether it is talking to a mind that answers
|
|
25
|
+
* requests or one that runs and hears whatever it is sent.
|
|
26
|
+
*/
|
|
27
|
+
mode: CognetSchedule
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The cognet slot as a caller hands it to `AxonBlueprint()`. The live
|
|
32
|
+
* definition says its own mode, so the slot may leave it out there; the
|
|
33
|
+
* normalised blueprint always has it.
|
|
34
|
+
*/
|
|
35
|
+
export type CognetBlueprintInput =
|
|
36
|
+
| (CognetSlot & Extract<CognetCarrier, { path: string }> & { mode: CognetSchedule })
|
|
37
|
+
| (CognetSlot & Extract<CognetCarrier, { definition: CognetDefinition }> & { mode?: CognetSchedule })
|
|
38
|
+
|
|
39
|
+
type CognetSlot = {
|
|
22
40
|
name: string
|
|
23
41
|
version: string
|
|
24
42
|
/** Kernel ABI contract the artifact targets — checked again at load from the definition itself. */
|
|
@@ -59,7 +77,17 @@ export type CognetBlueprint = {
|
|
|
59
77
|
* this is the copy the runtime plans with.
|
|
60
78
|
*/
|
|
61
79
|
engines?: EngineRequirements
|
|
62
|
-
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The services this brain uses, carried from its cognet.config.ts — and
|
|
83
|
+
* each one's interface as compiled: its name, and each method's kind and
|
|
84
|
+
* parameter names. What the kernel grants against before the brain
|
|
85
|
+
* loads, and serves calls by.
|
|
86
|
+
*/
|
|
87
|
+
uses?: Readonly<Record<string, CognetUse>>
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
type CognetCarrier =
|
|
63
91
|
| {
|
|
64
92
|
/** Absolute path to the compiled bundle — <agent>/.agent/cognet/cognet.mjs. */
|
|
65
93
|
path: string
|
|
@@ -70,4 +98,4 @@ export type CognetBlueprint = {
|
|
|
70
98
|
/** Live definition — test/embedded path. The CLI always emits path+hash. */
|
|
71
99
|
definition: CognetDefinition
|
|
72
100
|
}
|
|
73
|
-
|
|
101
|
+
|
package/src/cognet/cognet.ts
CHANGED
|
@@ -25,20 +25,22 @@ import type { EngineRequirements } from "../inference"
|
|
|
25
25
|
* - "invocation" — invoked once per admitted stimulus arrival, handed the
|
|
26
26
|
* full diff accumulated since the last invocation (may be more than one
|
|
27
27
|
* stimulus if several arrived while the previous wake was running).
|
|
28
|
-
* - "continuous" — invoked
|
|
29
|
-
* anything arrived; an empty diff is the ordinary steady state,
|
|
30
|
-
* edge case.
|
|
28
|
+
* - "continuous" — invoked on its own clock, `hz` times a second, regardless
|
|
29
|
+
* of whether anything arrived; an empty diff is the ordinary steady state,
|
|
30
|
+
* not an edge case.
|
|
31
31
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* the
|
|
37
|
-
*
|
|
32
|
+
* `hz` is the MIND'S rate — how often it is worth thinking — never the
|
|
33
|
+
* world's. How fast frames arrive is the body's, and the body only ever emits
|
|
34
|
+
* stimuli. The rate lived in the kernel once (`tickMs`, read by the
|
|
35
|
+
* scheduler: the runtime owning the brain's clock) and in the body once
|
|
36
|
+
* (`axon.tick()`: the body deciding how often a mind thinks); both were wrong
|
|
37
|
+
* for the same reason. It is declared HERE because this is the brain's own
|
|
38
|
+
* config, and the cognet host drives `kernel.wake()` at it. Every slower
|
|
39
|
+
* rhythm in the mind is a division of it — a system's own `rate`.
|
|
38
40
|
*/
|
|
39
41
|
export type CognetSchedule =
|
|
40
42
|
| { kind: "invocation" }
|
|
41
|
-
| { kind: "continuous" }
|
|
43
|
+
| { kind: "continuous"; hz: number }
|
|
42
44
|
|
|
43
45
|
/**
|
|
44
46
|
* When this brain can consume one input modality.
|
|
@@ -148,6 +150,65 @@ export type CognetConfig = {
|
|
|
148
150
|
*/
|
|
149
151
|
engines?: EngineRequirements
|
|
150
152
|
|
|
153
|
+
/**
|
|
154
|
+
* The weights this brain needs, by the names IT calls them.
|
|
155
|
+
*
|
|
156
|
+
* ```ts
|
|
157
|
+
* models: {
|
|
158
|
+
* features: { hf: "onnx-community/dinov2-small", set: true, capability: "vision", type: "transform", in: ["image"], out: ["vector"] },
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* The supply half of the indirection `engines:` makes for inference:
|
|
163
|
+
* `engines` says what a role is FOR, this says where a local provider can
|
|
164
|
+
* get something to fill it. A brain that shipped a provider identity would
|
|
165
|
+
* be a brain wired to one machine.
|
|
166
|
+
*
|
|
167
|
+
* Declaring weights is a STATIC fact about a mind, which is why the build
|
|
168
|
+
* reads it textually (`readCognetModels`) rather than by evaluating the
|
|
169
|
+
* config: a computed or imported specifier is deliberately not recognised.
|
|
170
|
+
* Keep the literal a literal.
|
|
171
|
+
*
|
|
172
|
+
* Fetched at `axon prepare`, verified against `sha256` when one is pinned,
|
|
173
|
+
* and stored once per hash — so two brains naming the same weights share
|
|
174
|
+
* the bytes.
|
|
175
|
+
*/
|
|
176
|
+
models?: Readonly<Record<string, ModelRef>>
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* The services this mind needs, by the names IT calls them, each bound to
|
|
180
|
+
* the interface that says what it means.
|
|
181
|
+
*
|
|
182
|
+
* ```ts
|
|
183
|
+
* uses: {
|
|
184
|
+
* main: { interface: "chat@1", requires: { context: { min: 100_000 } } },
|
|
185
|
+
* depth: { interface: "depth-metric@1", optional: true },
|
|
186
|
+
* scene: { interface: "./interfaces/scene@1" },
|
|
187
|
+
* }
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* The cognet names a contract, never a provider: the agent grants what
|
|
191
|
+
* fills each use. A required use with nothing to fill it fails at prepare;
|
|
192
|
+
* an optional one is unavailable, and a system asks before calling it.
|
|
193
|
+
*/
|
|
194
|
+
uses?: Readonly<Record<string, ServiceUse>>
|
|
195
|
+
|
|
196
|
+
/** A provider the cognet recommends for a use — offered to the agent, never required. */
|
|
197
|
+
suggests?: Readonly<Record<string, string>>
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Worker threads for systems that declare `thread: "worker"`.
|
|
201
|
+
*
|
|
202
|
+
* `"auto"` (the default) is two fewer than the machine's cores, at most
|
|
203
|
+
* four — the main thread and the rest of the machine keep the remainder.
|
|
204
|
+
* `0` runs every worker system on the main thread, in order: the same
|
|
205
|
+
* results, one core. A number is that many threads.
|
|
206
|
+
*
|
|
207
|
+
* Results never depend on this. Systems run in parallel only where the
|
|
208
|
+
* declared data says they cannot see each other, so one thread and four
|
|
209
|
+
* compute the same tick.
|
|
210
|
+
*/
|
|
211
|
+
threads?: "auto" | number
|
|
151
212
|
}
|
|
152
213
|
|
|
153
214
|
/**
|
|
@@ -198,7 +259,10 @@ export type ModelRef =
|
|
|
198
259
|
* This is what the generated entry hands CognetHost — never the author's
|
|
199
260
|
* cognet.config.ts on its own.
|
|
200
261
|
*/
|
|
201
|
-
export type CognetIdentity = Omit<CognetConfig, "abi"> & {
|
|
262
|
+
export type CognetIdentity = Omit<CognetConfig, "abi" | "uses"> & {
|
|
263
|
+
/** What the cognet uses, each joined to its interface as compiled — the compile step's, never the author's. */
|
|
264
|
+
uses?: Readonly<Record<string, CognetUse>>
|
|
265
|
+
|
|
202
266
|
/** Package name — from the cognet's package.json, never authored. */
|
|
203
267
|
name: string
|
|
204
268
|
|
|
@@ -224,3 +288,54 @@ export type CognetDefinition = CognetIdentity & {
|
|
|
224
288
|
/** Brain off. Nothing durable to flush — durable writes already happened at commit time. */
|
|
225
289
|
unload?(): Promise<void> | void
|
|
226
290
|
}
|
|
291
|
+
|
|
292
|
+
/** One service a cognet needs: the interface it means, and what breaks it when unmet. */
|
|
293
|
+
export type ServiceUse = {
|
|
294
|
+
/** `chat@1`, `depth-metric@1` — or the cognet's own, `./interfaces/scene@1`. */
|
|
295
|
+
interface: string
|
|
296
|
+
/** The mind runs without it. Absent: required. */
|
|
297
|
+
optional?: boolean
|
|
298
|
+
/** Bounds on what the provider's `describe()` reports, field by field. */
|
|
299
|
+
requires?: Readonly<Record<string, ServiceRequirement>>
|
|
300
|
+
/**
|
|
301
|
+
* The model that fills it, by the registry's id (`anthropic/claude-haiku-4.5`):
|
|
302
|
+
* one, or candidates in order, the first that some route of the user's
|
|
303
|
+
* carries being the one bound. Names WHAT model, never who serves it.
|
|
304
|
+
* Only for an interface the machine's engines serve.
|
|
305
|
+
*
|
|
306
|
+
* The author's default, never the last word: what the agent grants the
|
|
307
|
+
* use, and the user's pick for the primary, override it. A cognet can
|
|
308
|
+
* choose its models; it can't overrule the person whose machine it runs on.
|
|
309
|
+
*/
|
|
310
|
+
model?: string | readonly string[]
|
|
311
|
+
/**
|
|
312
|
+
* The use the user's model picker changes. At most one per cognet, across
|
|
313
|
+
* `engines` and `uses`. A role or use named `main` is the primary when
|
|
314
|
+
* none says so.
|
|
315
|
+
*/
|
|
316
|
+
primary?: boolean
|
|
317
|
+
/**
|
|
318
|
+
* The most calls it would make at once. A request, never a threshold: a
|
|
319
|
+
* machine with fewer slots serves them one after another, and
|
|
320
|
+
* `describe().slots` says how many it got.
|
|
321
|
+
*/
|
|
322
|
+
parallel?: number
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** What one field of `describe()` must be: exactly a value, within bounds, or holding each of a list. */
|
|
326
|
+
export type ServiceRequirement =
|
|
327
|
+
| string
|
|
328
|
+
| number
|
|
329
|
+
| boolean
|
|
330
|
+
| { min?: number; max?: number }
|
|
331
|
+
| { includes: ReadonlyArray<string | number> }
|
|
332
|
+
|
|
333
|
+
/** One use, as the runtime holds it: what the cognet declared, and its interface as compiled. */
|
|
334
|
+
export type CognetUse = ServiceUse & {
|
|
335
|
+
/** The interface's full name: `chat@1`, or `@cody/terry/scene@1` for the cognet's own. */
|
|
336
|
+
named: string
|
|
337
|
+
/** Each method's kind, and its parameters' names — the object a call's arguments are keyed by. */
|
|
338
|
+
methods: Readonly<Record<string, { kind: "describe" | "call" | "stream" | "session"; params: readonly string[] }>>
|
|
339
|
+
/** Where its conformance cases are, on this machine — absent for an interface that ships none. */
|
|
340
|
+
conformance?: string
|
|
341
|
+
}
|
package/src/cognet/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { CognetConfig, CognetIdentity, CognetDefinition, CognetSchedule, CognetStimulusCondition, CognetStimulusSupport, ModelRef } from "./cognet"
|
|
2
|
-
export type { CognetBlueprint } from "./blueprint"
|
|
1
|
+
export type { CognetConfig, CognetIdentity, CognetDefinition, CognetSchedule, CognetStimulusCondition, CognetStimulusSupport, ModelRef, ServiceUse, ServiceRequirement, CognetUse } from "./cognet"
|
|
2
|
+
export type { CognetBlueprint, CognetBlueprintInput } from "./blueprint"
|
|
3
3
|
export type { CognetHooks, CognetHookName, CognetPlugin, CognetPluginContext } from "./hooks"
|
package/src/config.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { DeployConfig } from "./deploy"
|
|
|
3
3
|
import { ModuleEntry } from "./module"
|
|
4
4
|
import { CognetConfig } from "./cognet/cognet"
|
|
5
5
|
import type { ProviderEntry } from "./tui"
|
|
6
|
+
import type { ServiceGrant } from "./services"
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Authoring configuration for an Axon agent.
|
|
@@ -70,9 +71,9 @@ export type AxonConfig<EventMap extends Record<string, unknown> = Record<string,
|
|
|
70
71
|
* falls back to ordinary ranking when the user's providers cannot supply
|
|
71
72
|
* it — so a published agent stays runnable by someone who has no Codex
|
|
72
73
|
* connection, rather than carrying its author's account setup as a hard
|
|
73
|
-
* dependency.
|
|
74
|
-
*
|
|
75
|
-
*
|
|
74
|
+
* dependency. An explicit pin overrides context and structured-output
|
|
75
|
+
* recommendations, consistently with live selection. Input/output
|
|
76
|
+
* compatibility is still required.
|
|
76
77
|
*
|
|
77
78
|
* A STRING, not a constructor call, because this is the one inference
|
|
78
79
|
* decision a user makes by hand and a picker edits by machine. The old
|
|
@@ -110,6 +111,23 @@ export type AxonConfig<EventMap extends Record<string, unknown> = Record<string,
|
|
|
110
111
|
*/
|
|
111
112
|
providers?: ProviderEntry[]
|
|
112
113
|
|
|
114
|
+
/**
|
|
115
|
+
* What fills each use the cognet declares, by the cognet's own name for it.
|
|
116
|
+
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* services: {
|
|
119
|
+
* main: { provider: "anthropic:claude-sonnet-5-5", limit: { calls: 600, per: "hour" } },
|
|
120
|
+
* depth: "auto",
|
|
121
|
+
* features: "./providers/features",
|
|
122
|
+
* hear: "off",
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* Absent, every use is `"auto"`. The agent decides — the cognet only says
|
|
127
|
+
* what it needs, and never learns what answered.
|
|
128
|
+
*/
|
|
129
|
+
services?: Readonly<Record<string, ServiceGrant>>
|
|
130
|
+
|
|
113
131
|
/**
|
|
114
132
|
* @deprecated Removed — use `model:` for a pin, `providers:` for sources.
|
|
115
133
|
*
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** Public account connection identities; OAuth Codex and OpenAI API are distinct. */
|
|
2
|
+
export const CONNECTION_PROVIDERS = {
|
|
3
|
+
codex: { name: "Codex", route: "codex", auth: "oauth", setupUrl: "https://chatgpt.com" },
|
|
4
|
+
openrouter: { name: "OpenRouter", route: "openrouter", auth: "key", setupUrl: "https://openrouter.ai/keys" },
|
|
5
|
+
anthropic: { name: "Anthropic", route: "anthropic", auth: "key", setupUrl: "https://platform.claude.com/settings/keys" },
|
|
6
|
+
"openai-api": { name: "OpenAI API", route: "openai", auth: "key", setupUrl: "https://platform.openai.com/api-keys" },
|
|
7
|
+
google: { name: "Google", route: "google", auth: "key", setupUrl: "https://aistudio.google.com/apikey" },
|
|
8
|
+
groq: { name: "Groq", route: "groq", auth: "key", setupUrl: "https://console.groq.com/keys" },
|
|
9
|
+
cerebras: { name: "Cerebras", route: "cerebras", auth: "key", setupUrl: "https://cloud.cerebras.ai" },
|
|
10
|
+
mistral: { name: "Mistral", route: "mistral", auth: "key", setupUrl: "https://console.mistral.ai" },
|
|
11
|
+
deepseek: { name: "DeepSeek", route: "deepseek", auth: "key", setupUrl: "https://platform.deepseek.com/api_keys" },
|
|
12
|
+
xai: { name: "xAI", route: "xai", auth: "key", setupUrl: "https://console.x.ai" },
|
|
13
|
+
perplexity: { name: "Perplexity", route: "perplexity", auth: "key", setupUrl: "https://www.perplexity.ai/settings/api" },
|
|
14
|
+
zai: { name: "Z.AI", route: "zai", auth: "key", setupUrl: "https://z.ai/manage-apikey/apikey-list" },
|
|
15
|
+
moonshot: { name: "Moonshot", route: "moonshot", auth: "key", setupUrl: "https://platform.moonshot.ai" },
|
|
16
|
+
} as const
|
|
17
|
+
|
|
18
|
+
export type ConnectionProvider = keyof typeof CONNECTION_PROVIDERS
|
|
19
|
+
export type KeyConnectionProvider = Exclude<ConnectionProvider, "codex">
|
|
20
|
+
|
|
21
|
+
export function isConnectionProvider(value: string): value is ConnectionProvider {
|
|
22
|
+
return Object.hasOwn(CONNECTION_PROVIDERS, value)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Credential material is transient host memory; revision is an opaque cache identity. */
|
|
26
|
+
export type ProviderCredential = {
|
|
27
|
+
accessToken: string
|
|
28
|
+
expiresAt: number
|
|
29
|
+
revision: string
|
|
30
|
+
accountId?: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ProviderConnection = {
|
|
34
|
+
provider: ConnectionProvider
|
|
35
|
+
route: string
|
|
36
|
+
connectedAt: number
|
|
37
|
+
updatedAt: number
|
|
38
|
+
revision: string
|
|
39
|
+
status: "active" | "broken"
|
|
40
|
+
/** Stored means no documented, non-billable authentication probe is available. */
|
|
41
|
+
verification: "verified" | "stored"
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const ERRORS = {
|
|
45
|
+
VAULT_PROVIDER_UNKNOWN: { status: 404, message: "This provider connection is not supported." },
|
|
46
|
+
VAULT_CREDENTIAL_INVALID: { status: 400, message: "The provider rejected this credential. Check it and try again." },
|
|
47
|
+
VAULT_PROVIDER_FORBIDDEN: { status: 403, message: "This credential does not have permission to verify the provider connection." },
|
|
48
|
+
VAULT_VERIFY_UNAVAILABLE: { status: 503, message: "The provider could not verify the connection. Try again later." },
|
|
49
|
+
VAULT_CONNECTION_NOT_FOUND: { status: 404, message: "This provider is not connected. Connect it to your Axon account first." },
|
|
50
|
+
VAULT_CONNECTION_BROKEN: { status: 409, message: "This provider connection needs to be reconnected." },
|
|
51
|
+
VAULT_IDENTITY_CHANGED: { status: 409, message: "The signed-in account changed during this operation. Try again." },
|
|
52
|
+
VAULT_CONNECTION_CHANGED: { status: 409, message: "This provider connection changed during this operation. Try again." },
|
|
53
|
+
VAULT_CREDENTIAL_ENDPOINT: { status: 400, message: "A custom endpoint requires an explicit credential. Account credentials cannot be sent to an endpoint override." },
|
|
54
|
+
VAULT_RESPONSE_INVALID: { status: 502, message: "The provider connection service returned an invalid response." },
|
|
55
|
+
} as const
|
|
56
|
+
|
|
57
|
+
/** Safe boundary errors; never include provider response bodies or credential input. */
|
|
58
|
+
export class VaultConnectionError extends Error {
|
|
59
|
+
readonly code: keyof typeof ERRORS
|
|
60
|
+
readonly statusCode: number
|
|
61
|
+
readonly provider: string
|
|
62
|
+
|
|
63
|
+
constructor(code: keyof typeof ERRORS, provider: string) {
|
|
64
|
+
super(ERRORS[code].message)
|
|
65
|
+
this.name = "VaultConnectionError"
|
|
66
|
+
this.code = code
|
|
67
|
+
this.statusCode = ERRORS[code].status
|
|
68
|
+
this.provider = provider
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/define.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AxonEngineDriver, AxonTransformDriver } from "./engine"
|
|
1
2
|
import type { AxonConfig } from "./config"
|
|
2
3
|
import type { BenchConfig, BenchDefinition } from "./bench"
|
|
3
4
|
import type { ModuleConfig, ModuleEmitMap, ModuleOptionSchema } from "./module"
|
|
@@ -285,3 +286,36 @@ export type AxonTestHandle = {
|
|
|
285
286
|
* @see https://axon.arclabs.it/docs/v2/agent/testing
|
|
286
287
|
*/
|
|
287
288
|
export type AxonTest = () => Promise<AxonTestHandle>
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* A provider the agent writes — the default export of `providers/<name>.provider.ts`.
|
|
292
|
+
* It implements one interface: say which, and write its methods as the
|
|
293
|
+
* interface does — that every method is there is checked when it is granted,
|
|
294
|
+
* and that each answers as the interface means by `axon conform`. What it
|
|
295
|
+
* needs of the machine it declares in `engines`, as a cognet declares roles —
|
|
296
|
+
* resolved against the machine's models, never bundled — and its methods
|
|
297
|
+
* reach them as `this.engines`.
|
|
298
|
+
*
|
|
299
|
+
* ```ts
|
|
300
|
+
* export default defineProvider({
|
|
301
|
+
* implements: "@cody/terry/features@1",
|
|
302
|
+
* engines: { dino: { type: "transform", in: "image", out: "features" } },
|
|
303
|
+
* describe: () => ({ patch: 16 }),
|
|
304
|
+
* async extract(picture: Picture) { return this.engines.dino.transform(…) },
|
|
305
|
+
* })
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
export function defineProvider<const E extends Readonly<Record<string, ProviderEngine>> = {}>(
|
|
309
|
+
definition: {
|
|
310
|
+
implements: string
|
|
311
|
+
engines?: E
|
|
312
|
+
describe(): Readonly<Record<string, unknown>>
|
|
313
|
+
release?(handle: string): Promise<void>
|
|
314
|
+
[method: string]: unknown
|
|
315
|
+
} & ThisType<{ engines: { [K in keyof E]: E[K]["type"] extends "transform" ? AxonTransformDriver : AxonEngineDriver } }>,
|
|
316
|
+
): typeof definition {
|
|
317
|
+
return definition
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** One engine a provider needs of the machine — as a cognet's `engines:` writes a role. */
|
|
321
|
+
export type ProviderEngine = { type: "generate" | "transform"; in: string | readonly string[]; out: string | readonly string[] }
|
package/src/engine.ts
CHANGED
|
@@ -84,8 +84,8 @@ export type EngineResources = {
|
|
|
84
84
|
* The runtime's cloud client — engines call what they need (vault
|
|
85
85
|
* connection tokens today; engine resolution and the Cognos connection
|
|
86
86
|
* when the Axon engine is ported). Provider tokens are minted
|
|
87
|
-
* server-side and cached
|
|
88
|
-
*
|
|
87
|
+
* server-side and cached for at most 30 seconds. Credential revisions
|
|
88
|
+
* replace SDK clients when keys rotate without rebuilding the driver.
|
|
89
89
|
*/
|
|
90
90
|
cloud: EngineCloud
|
|
91
91
|
}
|
|
@@ -98,8 +98,16 @@ export type EngineResources = {
|
|
|
98
98
|
*/
|
|
99
99
|
export type EngineCloud = {
|
|
100
100
|
user: {
|
|
101
|
+
/** Metadata-only account reporting; absent for embedded or offline hosts. */
|
|
102
|
+
usage?: { record(input: import("./provider-usage").ProviderUsageRecord): Promise<void> }
|
|
103
|
+
/** Account state when supplied by a full host client. Explicit-only embedders may omit it. */
|
|
104
|
+
auth?: { readonly token: string | undefined; readonly user?: { id: string } }
|
|
101
105
|
vault: {
|
|
102
106
|
connections: {
|
|
107
|
+
/** Active account metadata; no credential values. Hosts may omit this seam for explicit-only inference. */
|
|
108
|
+
list?(): Promise<import("./connections").ProviderConnection[]>
|
|
109
|
+
/** Generic credential read, backed by an identity-scoped memory cache. */
|
|
110
|
+
credential?(provider: import("./connections").ConnectionProvider): Promise<import("./connections").ProviderCredential>
|
|
103
111
|
openai: {
|
|
104
112
|
/** Narrow short-lived Codex token — refresh material never reaches a host. Throws when the account isn't connected. */
|
|
105
113
|
token(): Promise<CodexToken>
|
|
@@ -210,6 +218,8 @@ export type CodexToken = {
|
|
|
210
218
|
* handles, never model-visible content.
|
|
211
219
|
*/
|
|
212
220
|
export type AxonEngineDriver = {
|
|
221
|
+
/** Reasoning effort actually configured on this driver, when known. */
|
|
222
|
+
readonly effort?: EngineEffort
|
|
213
223
|
/**
|
|
214
224
|
* Absent on the generate driver, deliberately.
|
|
215
225
|
*
|
|
@@ -238,6 +248,21 @@ export type AxonEngineDriver = {
|
|
|
238
248
|
*/
|
|
239
249
|
export type AxonDriver = AxonEngineDriver | AxonTransformDriver | AxonStreamDriver
|
|
240
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Inference performed OUTSIDE this process — a confined agent's engines,
|
|
253
|
+
* one factory per handle kind. The agent names a role; what fills it, and
|
|
254
|
+
* the credential that pays for it, stay on the other side.
|
|
255
|
+
*
|
|
256
|
+
* Stream engines have no factory yet: a session's hidden state would have
|
|
257
|
+
* to live across the boundary, and until that is designed a confined agent
|
|
258
|
+
* asking for one is refused by name rather than handed something that half
|
|
259
|
+
* works.
|
|
260
|
+
*/
|
|
261
|
+
export type RemoteEngines = {
|
|
262
|
+
generate(role: string): AxonEngineDriver
|
|
263
|
+
transform(role: string): AxonTransformDriver
|
|
264
|
+
}
|
|
265
|
+
|
|
241
266
|
/**
|
|
242
267
|
* One shot in, one shot out.
|
|
243
268
|
*
|
|
@@ -249,7 +274,11 @@ export type AxonDriver = AxonEngineDriver | AxonTransformDriver | AxonStreamDriv
|
|
|
249
274
|
*/
|
|
250
275
|
export type AxonTransformDriver = {
|
|
251
276
|
readonly kind: "transform"
|
|
252
|
-
transform(input: unknown, opts?: {
|
|
277
|
+
transform(input: unknown, opts?: {
|
|
278
|
+
onProgress?: (progress: { fraction?: number; message?: string }) => void
|
|
279
|
+
/** The wake's cancellation — a transform crossing a process boundary must stop when its wake does. */
|
|
280
|
+
signal?: AbortSignal
|
|
281
|
+
}): Promise<unknown>
|
|
253
282
|
}
|
|
254
283
|
|
|
255
284
|
/**
|
|
@@ -431,6 +460,7 @@ export type AxonEngineMeta = {
|
|
|
431
460
|
|
|
432
461
|
/** Stable failure vocabulary shared by drivers, the kernel log, and clients. */
|
|
433
462
|
export type AxonEngineFaultCode =
|
|
463
|
+
| "USAGE_REPORT_FAILED"
|
|
434
464
|
| "EMPTY_RESPONSE"
|
|
435
465
|
| "TRANSPORT"
|
|
436
466
|
| "RATE_LIMIT"
|
package/src/error.ts
CHANGED
|
@@ -31,6 +31,11 @@ export type AxonStackFrame = {
|
|
|
31
31
|
export type AxonErrorSource =
|
|
32
32
|
| "runtime" | "manifest" | "capsule" | "server" | "thread" | "cli"
|
|
33
33
|
| "cloud" | "kernel" | "cognet" | "tui" | "bench"
|
|
34
|
+
// The memory substrate. Its own source rather than "runtime": a Locus
|
|
35
|
+
// failure is about the BASIS — the coordinate system stored beliefs are
|
|
36
|
+
// expressed in — and telling "your ontology changed, migrate" apart from
|
|
37
|
+
// "the runtime broke" is the difference between a sleep task and a bug.
|
|
38
|
+
| "locus"
|
|
34
39
|
/**
|
|
35
40
|
* A third-party inference provider — the user's own Codex, OpenRouter,
|
|
36
41
|
* Ollama or Axon route.
|
|
@@ -52,6 +57,12 @@ export type AxonErrorSource =
|
|
|
52
57
|
// and telling that apart from one agent's runtime fault is the difference
|
|
53
58
|
// between "restart your agent" and "start the daemon".
|
|
54
59
|
| "daemon"
|
|
60
|
+
/**
|
|
61
|
+
* A body, or the contract it speaks (`body/body.ts`). Its own source: a
|
|
62
|
+
* body that sends what the contract does not allow is the body's bug —
|
|
63
|
+
* a mod's, a bridge's — never the runtime's or the mind's.
|
|
64
|
+
*/
|
|
65
|
+
| "body"
|
|
55
66
|
|
|
56
67
|
/** Lifecycle impact of an error. */
|
|
57
68
|
export type AxonErrorSeverity = "fatal" | "recovered" | "degraded"
|
package/src/handle.ts
CHANGED
|
@@ -303,6 +303,23 @@ export type AxonHandle = {
|
|
|
303
303
|
/** Streaming agent invocation — yields entries as they happen. */
|
|
304
304
|
stream(input: AxonRequestInput | string): AxonRun
|
|
305
305
|
|
|
306
|
+
/**
|
|
307
|
+
* Talk to the running mind as one client, at one address.
|
|
308
|
+
*
|
|
309
|
+
* A connection is not a request: nothing waits for a reply to end. You
|
|
310
|
+
* say things, and the mind says things — answers, and anything else it
|
|
311
|
+
* decides to say — as and when it does. Works for any mind; the one way
|
|
312
|
+
* to talk to a continuous one, which has no request lifecycle at all.
|
|
313
|
+
*
|
|
314
|
+
* ```ts
|
|
315
|
+
* const terminal = axon.connect({ channel: "terminal" })
|
|
316
|
+
* terminal.on("cognet:output:text", data => render(data))
|
|
317
|
+
* terminal.activity(working => spinner(working.length > 0))
|
|
318
|
+
* await terminal.send("what's in this repo?")
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
connect(at: { channel: string }): AxonConnection
|
|
322
|
+
|
|
306
323
|
/**
|
|
307
324
|
* Deliver a stimulus — the agent's sense door, and the only way the
|
|
308
325
|
* environment reaches cognition.
|
|
@@ -329,6 +346,38 @@ export type AxonHandle = {
|
|
|
329
346
|
*/
|
|
330
347
|
stim<K extends AxonStimulusType>(type: K, data: AxonStimulusEvent[K]): Promise<AxonEntry>
|
|
331
348
|
|
|
349
|
+
/**
|
|
350
|
+
* Heavy bytes a stimulus refers to rather than carries.
|
|
351
|
+
*
|
|
352
|
+
* ```ts
|
|
353
|
+
* const ref = await axon.media.keep(jpeg, "image/jpeg")
|
|
354
|
+
* axon.stim("cognet:stimulus:visual", { channel: "/vision", ref: ref, kind: "image" })
|
|
355
|
+
* ```
|
|
356
|
+
*
|
|
357
|
+
* The bytes are written once, beside the session, in a bounded window;
|
|
358
|
+
* the event stays small on every wire it crosses, and the cognet reads
|
|
359
|
+
* the file only when it looks.
|
|
360
|
+
*/
|
|
361
|
+
media: {
|
|
362
|
+
keep(bytes: Uint8Array, mime: string): Promise<import("./session").StimulusRef>
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* The body this agent wears — told by whatever connects it to one (the
|
|
367
|
+
* body module). `wear` takes the body's manifest as the body sent it,
|
|
368
|
+
* checks it, and from then on it is what `kernel.body()` reports; a body
|
|
369
|
+
* that describes itself again is worn again. `present` says whether the
|
|
370
|
+
* worn body is the mind's to move — embodied, held or overridden — and
|
|
371
|
+
* is what `kernel.presence()` reports. `leave` says it is gone. All are
|
|
372
|
+
* recorded in the session, so a replay knows what body every reading came
|
|
373
|
+
* from, and whether it was the mind's.
|
|
374
|
+
*/
|
|
375
|
+
body: {
|
|
376
|
+
wear(manifest: unknown): Promise<import("./body/body").Manifest>
|
|
377
|
+
present(presence: Exclude<import("./body/body").Presence, { state: "detached" }>): Promise<void>
|
|
378
|
+
leave(why: string): Promise<void>
|
|
379
|
+
}
|
|
380
|
+
|
|
332
381
|
/**
|
|
333
382
|
* Observe what the brain emits — the counterpart to `stim()`.
|
|
334
383
|
*
|
|
@@ -419,6 +468,12 @@ export type AxonHandle = {
|
|
|
419
468
|
readonly log: readonly AxonSessionEvent[]
|
|
420
469
|
/** Internal tick/phase/system telemetry — the firehose behind devtools and flame graphs. */
|
|
421
470
|
readonly kernelLog: readonly AxonKernelEvent[]
|
|
471
|
+
/**
|
|
472
|
+
* The oldest seq `kernelLog` still holds — it is a window of recent
|
|
473
|
+
* telemetry, not the session. 0 until it first trims; older events are
|
|
474
|
+
* on disk only.
|
|
475
|
+
*/
|
|
476
|
+
readonly kernelFloor: number
|
|
422
477
|
}
|
|
423
478
|
}
|
|
424
479
|
|
|
@@ -431,3 +486,15 @@ export type AxonHandle = {
|
|
|
431
486
|
export type AxonCapsuleHandle = AxonAmbient & {
|
|
432
487
|
request(input: AxonRequestInput | string): Promise<AxonResult>
|
|
433
488
|
}
|
|
489
|
+
|
|
490
|
+
/** One client's line to a running mind — see `AxonHandle.connect`. */
|
|
491
|
+
export type AxonConnection = {
|
|
492
|
+
/** Say something. Resolves when the mind has it, never when it has answered. */
|
|
493
|
+
send(content: string | string[]): Promise<void>
|
|
494
|
+
/** What the mind outputs to this client's channel, or to no one in particular. Returns an unsubscribe. */
|
|
495
|
+
on<K extends keyof AxonOutputEvent>(type: K, handler: (data: AxonOutputEvent[K]) => void | Promise<void>): () => void
|
|
496
|
+
/** What the mind is working on beside its ticks, each time that changes. Empty: idle. Returns an unsubscribe. */
|
|
497
|
+
activity(handler: (working: string[]) => void): () => void
|
|
498
|
+
/** Stop what the mind is working on. */
|
|
499
|
+
interrupt(): void
|
|
500
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export * from "./blueprint"
|
|
2
2
|
export * from "./config"
|
|
3
3
|
export * from "./connect"
|
|
4
|
+
export * from "./connections"
|
|
4
5
|
export * from "./define"
|
|
5
6
|
export * from "./deploy"
|
|
6
7
|
export * from "./engine"
|
|
7
8
|
export * from "./inference"
|
|
9
|
+
export * from "./services"
|
|
10
|
+
export * from "./usage"
|
|
8
11
|
export * from "./error"
|
|
9
12
|
export * from "./report"
|
|
10
13
|
export * from "./http"
|
|
@@ -32,6 +35,8 @@ export * from "./cognet"
|
|
|
32
35
|
export * from "./tools"
|
|
33
36
|
export * from "./tui"
|
|
34
37
|
export * from "./bench"
|
|
38
|
+
export * as body from "./body/body"
|
|
39
|
+
export * as world from "./world/world"
|
|
35
40
|
export * from "./policy-shell"
|
|
36
41
|
|
|
37
42
|
/**
|
|
@@ -39,3 +44,6 @@ export * from "./policy-shell"
|
|
|
39
44
|
* deployed. See agent-handle.ts for why the transports share a type.
|
|
40
45
|
*/
|
|
41
46
|
export type { AxonAgentHandle, AxonAuthoringHandle, AxonMirroredSession, AxonSessionHandlers } from "./agent-handle"
|
|
47
|
+
export { ProviderUsageWire } from "./provider-usage"
|
|
48
|
+
export type { ProviderUsageRecord, ProviderUsageCount, ProviderUsageSummary } from "./provider-usage"
|
|
49
|
+
export { machineStatement, type MachineDistribution } from "./machine"
|