@tangle-network/agent-interface 5.10.18 → 5.10.20
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/dist/environment-lifetime.d.ts +3 -1
- package/dist/environment-observation.d.ts +3 -3
- package/dist/environment-provider.d.ts +1 -0
- package/dist/environment-provider.js +1 -0
- package/dist/environment-requests.d.ts +19 -0
- package/dist/environment-requests.js +65 -0
- package/dist/environment-runtime.d.ts +49 -94
- package/dist/environment-runtime.js +3 -92
- package/dist/execution-failure.d.ts +13 -0
- package/dist/execution-failure.js +8 -0
- package/dist/harness-capabilities.d.ts +1 -8
- package/dist/harness-capabilities.js +10 -24
- package/dist/profile-kb/index.d.ts +2 -4
- package/dist/profile-kb/index.js +3 -40
- package/dist/profile-kb/models.d.ts +4 -0
- package/dist/profile-kb/models.js +44 -0
- package/dist/profile-kb/types.d.ts +2 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Lifecycle bounds a caller may place on one environment create (#309).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Bounds use whole seconds — a millisecond value that is not a whole second is
|
|
5
5
|
* refused, so a caller never believes a sub-second bound was honored. A
|
|
6
6
|
* provider that cannot enforce a requested bound fails the create rather than
|
|
7
7
|
* dropping the field; one whose platform caps the value honors the shorter.
|
|
@@ -11,4 +11,6 @@ export interface AgentEnvironmentLifetime {
|
|
|
11
11
|
maxLifetimeMs?: number;
|
|
12
12
|
/** After this long with no caller activity the platform may suspend or stop the environment. */
|
|
13
13
|
idleTimeoutMs?: number;
|
|
14
|
+
/** Delete the sealed stopped generation after this platform-owned retention interval. */
|
|
15
|
+
deleteAfterStoppedMs?: number;
|
|
14
16
|
}
|
|
@@ -121,8 +121,8 @@ export declare const EnvironmentLifecycleSchema: z.ZodObject<{
|
|
|
121
121
|
resumable: z.ZodBoolean;
|
|
122
122
|
mode: z.ZodOptional<z.ZodEnum<{
|
|
123
123
|
none: "none";
|
|
124
|
-
native: "native";
|
|
125
124
|
replayed: "replayed";
|
|
125
|
+
native: "native";
|
|
126
126
|
}>>;
|
|
127
127
|
}, z.core.$strict>>;
|
|
128
128
|
persistence: z.ZodOptional<z.ZodObject<{
|
|
@@ -445,8 +445,8 @@ export declare const AgentEnvironmentObservationSchema: z.ZodObject<{
|
|
|
445
445
|
resumable: z.ZodBoolean;
|
|
446
446
|
mode: z.ZodOptional<z.ZodEnum<{
|
|
447
447
|
none: "none";
|
|
448
|
-
native: "native";
|
|
449
448
|
replayed: "replayed";
|
|
449
|
+
native: "native";
|
|
450
450
|
}>>;
|
|
451
451
|
}, z.core.$strict>>;
|
|
452
452
|
persistence: z.ZodOptional<z.ZodObject<{
|
|
@@ -493,8 +493,8 @@ export declare const AgentEnvironmentObservationSchema: z.ZodObject<{
|
|
|
493
493
|
resumable: z.ZodBoolean;
|
|
494
494
|
mode: z.ZodOptional<z.ZodEnum<{
|
|
495
495
|
none: "none";
|
|
496
|
-
native: "native";
|
|
497
496
|
replayed: "replayed";
|
|
497
|
+
native: "native";
|
|
498
498
|
}>>;
|
|
499
499
|
}, z.core.$strict>>;
|
|
500
500
|
persistence: z.ZodOptional<z.ZodObject<{
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Sha256Digest } from "./agent-candidate.js";
|
|
2
|
+
import type { CreateAgentEnvironmentInput } from "./environment-runtime.js";
|
|
1
3
|
import { z } from "zod";
|
|
2
4
|
import type { WorkspaceCwd } from "./workspace-cwd.js";
|
|
3
5
|
import { type WorkspaceCheckpointRef } from "./workspace-checkpoint.js";
|
|
@@ -241,3 +243,20 @@ export interface PlacementInfo {
|
|
|
241
243
|
region?: string;
|
|
242
244
|
providerMetadata?: Record<string, unknown>;
|
|
243
245
|
}
|
|
246
|
+
/** Canonical create identity excludes the operation key and per-attempt abort signal.
|
|
247
|
+
* Keyed creates require canonical JSON; unkeyed creates may retain opaque mapper values.
|
|
248
|
+
* @internal */
|
|
249
|
+
export declare function agentEnvironmentCreateInputDigest(input: CreateAgentEnvironmentInput): Sha256Digest;
|
|
250
|
+
/** @internal State held by one provider adapter for keyed create retries. */
|
|
251
|
+
export interface AgentEnvironmentCreateIdempotencyRecord<T> {
|
|
252
|
+
readonly digest: Sha256Digest;
|
|
253
|
+
readonly pending: Promise<T>;
|
|
254
|
+
environment?: T;
|
|
255
|
+
}
|
|
256
|
+
/** Coalesce concurrent keyed creates and reject changed-input collisions before another create effect.
|
|
257
|
+
* The backing service retains keys across adapter reconstruction.
|
|
258
|
+
* The creating call keeps the provider's verdict; subsequent same-key calls receive a replayed view.
|
|
259
|
+
* Keyed callbacks receive an immutable canonical JSON snapshot shared by their digest, so later caller
|
|
260
|
+
* mutation cannot change accepted input. Unkeyed callbacks retain opaque mapper values by identity.
|
|
261
|
+
* @internal */
|
|
262
|
+
export declare function createAgentEnvironmentWithIdempotency<T extends object>(records: Map<string, AgentEnvironmentCreateIdempotencyRecord<T>>, input: CreateAgentEnvironmentInput, create: (input: CreateAgentEnvironmentInput) => Promise<T>): Promise<T>;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { canonicalCandidateDigest, canonicalCandidateJson } from "./agent-candidate-schema-common.js";
|
|
2
|
+
import { deepFreeze } from "./deep-freeze.js";
|
|
1
3
|
import { z } from "zod";
|
|
2
4
|
import { boundedIdentifierSchema, boundedJsonRecordSchema, boundedStringSchema, CONTRACT_MAX_ARRAY_LENGTH, } from "./contract-limits.js";
|
|
3
5
|
import { workspaceCwdSchema } from "./workspace-cwd.js";
|
|
@@ -65,3 +67,66 @@ export const ResourceRequestSchema = z.strictObject({
|
|
|
65
67
|
gpu: boundedIdentifierSchema.optional(),
|
|
66
68
|
providerOptions: boundedJsonRecordSchema.optional(),
|
|
67
69
|
});
|
|
70
|
+
/** Canonical create identity excludes the operation key and per-attempt abort signal.
|
|
71
|
+
* Keyed creates require canonical JSON; unkeyed creates may retain opaque mapper values.
|
|
72
|
+
* @internal */
|
|
73
|
+
export function agentEnvironmentCreateInputDigest(input) {
|
|
74
|
+
const { idempotencyKey: _idempotencyKey, signal: _signal, ...material } = input;
|
|
75
|
+
return canonicalCandidateDigest({
|
|
76
|
+
kind: "agent-environment-create.v1",
|
|
77
|
+
input: material,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** Same-key callers share one environment, with creation:"replayed" because they provisioned nothing.
|
|
81
|
+
* Members must not read this; shallow replay views reject classes whose prototype would be lost.
|
|
82
|
+
* @internal */
|
|
83
|
+
function replayedAgentEnvironmentView(environment) {
|
|
84
|
+
const prototype = Object.getPrototypeOf(environment);
|
|
85
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
86
|
+
throw new Error("a replayed agent environment view requires a plain object environment");
|
|
87
|
+
}
|
|
88
|
+
return { ...environment, creation: "replayed" };
|
|
89
|
+
}
|
|
90
|
+
/** Coalesce concurrent keyed creates and reject changed-input collisions before another create effect.
|
|
91
|
+
* The backing service retains keys across adapter reconstruction.
|
|
92
|
+
* The creating call keeps the provider's verdict; subsequent same-key calls receive a replayed view.
|
|
93
|
+
* Keyed callbacks receive an immutable canonical JSON snapshot shared by their digest, so later caller
|
|
94
|
+
* mutation cannot change accepted input. Unkeyed callbacks retain opaque mapper values by identity.
|
|
95
|
+
* @internal */
|
|
96
|
+
export async function createAgentEnvironmentWithIdempotency(records, input, create) {
|
|
97
|
+
const { idempotencyKey: key, signal, ...material } = input;
|
|
98
|
+
signal?.throwIfAborted();
|
|
99
|
+
if (key === undefined)
|
|
100
|
+
return create(input);
|
|
101
|
+
const snapshot = deepFreeze(JSON.parse(canonicalCandidateJson(material)));
|
|
102
|
+
const acceptedInput = Object.freeze({
|
|
103
|
+
...snapshot,
|
|
104
|
+
idempotencyKey: key,
|
|
105
|
+
...(signal === undefined ? {} : { signal }),
|
|
106
|
+
});
|
|
107
|
+
const digest = agentEnvironmentCreateInputDigest(acceptedInput);
|
|
108
|
+
const existing = records.get(key);
|
|
109
|
+
if (existing !== undefined) {
|
|
110
|
+
if (existing.digest !== digest) {
|
|
111
|
+
throw new Error("agent environment create idempotency key conflicts with a different create input");
|
|
112
|
+
}
|
|
113
|
+
return replayedAgentEnvironmentView(existing.environment ?? (await existing.pending));
|
|
114
|
+
}
|
|
115
|
+
const pending = Promise.resolve().then(() => create(acceptedInput));
|
|
116
|
+
const record = {
|
|
117
|
+
digest,
|
|
118
|
+
pending,
|
|
119
|
+
};
|
|
120
|
+
records.set(key, record);
|
|
121
|
+
try {
|
|
122
|
+
const environment = await pending;
|
|
123
|
+
if (records.get(key) === record)
|
|
124
|
+
record.environment = environment;
|
|
125
|
+
return environment;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (records.get(key) === record)
|
|
129
|
+
records.delete(key);
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { type AgentTurnFailure } from "./execution-failure.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { type ProxySecretBinding, type ProxySecretCapabilities, type ProxySecretReceipt, type ProxySecretParents } from "./proxy-secrets.js";
|
|
3
4
|
import type { AgentRuntimeAttachments } from "./runtime-attachments.js";
|
|
4
5
|
import type { AgentEnvironmentLifetime } from "./environment-lifetime.js";
|
|
5
6
|
export { AgentRuntimeAttachmentsSchema, type AgentRuntimeAttachments } from "./runtime-attachments.js";
|
|
6
|
-
import type { AgentCandidateArtifactPort
|
|
7
|
+
import type { AgentCandidateArtifactPort } from "./agent-candidate.js";
|
|
7
8
|
import type { AgentProfile, AgentProfileCapabilities, AgentProfileValidationResult } from "./agent-profile.js";
|
|
8
9
|
import type { InputPart } from "./parts.js";
|
|
9
10
|
import type { StreamEvent } from "./stream-events.js";
|
|
@@ -884,6 +885,7 @@ export interface AgentTurnResult {
|
|
|
884
885
|
text: string;
|
|
885
886
|
success: boolean;
|
|
886
887
|
error?: string;
|
|
888
|
+
failure?: AgentTurnFailure;
|
|
887
889
|
sessionId?: string;
|
|
888
890
|
usage?: TokenUsage;
|
|
889
891
|
metadata?: Record<string, unknown>;
|
|
@@ -895,6 +897,17 @@ export declare const AgentTurnResultSchema: z.ZodObject<{
|
|
|
895
897
|
text: z.ZodCustom<string, string>;
|
|
896
898
|
success: z.ZodBoolean;
|
|
897
899
|
error: z.ZodOptional<z.ZodString>;
|
|
900
|
+
failure: z.ZodOptional<z.ZodObject<{
|
|
901
|
+
kind: z.ZodEnum<{
|
|
902
|
+
capacity: "capacity";
|
|
903
|
+
caller: "caller";
|
|
904
|
+
infra: "infra";
|
|
905
|
+
work: "work";
|
|
906
|
+
}>;
|
|
907
|
+
code: z.ZodString;
|
|
908
|
+
resetAt: z.ZodOptional<z.ZodISODateTime>;
|
|
909
|
+
retryAfterMs: z.ZodOptional<z.ZodNumber>;
|
|
910
|
+
}, z.core.$strict>>;
|
|
898
911
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
899
912
|
usage: z.ZodOptional<z.ZodObject<{
|
|
900
913
|
inputTokens: z.ZodNumber;
|
|
@@ -1053,6 +1066,17 @@ export declare const AgentNativeContextContinuationResultSchema: z.ZodUnion<read
|
|
|
1053
1066
|
text: z.ZodCustom<string, string>;
|
|
1054
1067
|
success: z.ZodBoolean;
|
|
1055
1068
|
error: z.ZodOptional<z.ZodString>;
|
|
1069
|
+
failure: z.ZodOptional<z.ZodObject<{
|
|
1070
|
+
kind: z.ZodEnum<{
|
|
1071
|
+
capacity: "capacity";
|
|
1072
|
+
caller: "caller";
|
|
1073
|
+
infra: "infra";
|
|
1074
|
+
work: "work";
|
|
1075
|
+
}>;
|
|
1076
|
+
code: z.ZodString;
|
|
1077
|
+
resetAt: z.ZodOptional<z.ZodISODateTime>;
|
|
1078
|
+
retryAfterMs: z.ZodOptional<z.ZodNumber>;
|
|
1079
|
+
}, z.core.$strict>>;
|
|
1056
1080
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
1057
1081
|
usage: z.ZodOptional<z.ZodObject<{
|
|
1058
1082
|
inputTokens: z.ZodNumber;
|
|
@@ -1345,12 +1369,8 @@ export interface AgentEnvironment {
|
|
|
1345
1369
|
readonly id: string;
|
|
1346
1370
|
readonly provider: string;
|
|
1347
1371
|
readonly name?: string;
|
|
1348
|
-
/**
|
|
1349
|
-
*
|
|
1350
|
-
* per-call fact: a same-key replay returns a view of the same environment
|
|
1351
|
-
* with `creation: "replayed"`. Absent on `get()` results and when the
|
|
1352
|
-
* provider cannot prove which outcome happened.
|
|
1353
|
-
*/
|
|
1372
|
+
/** Per-create verdict: a same-key replay returns this environment with creation:"replayed".
|
|
1373
|
+
* Absent on get() or when the provider cannot prove the create's outcome. */
|
|
1354
1374
|
readonly creation?: AgentEnvironmentCreation;
|
|
1355
1375
|
/** Authoritative receipt returned only by a qualified context-transfer attachment. */
|
|
1356
1376
|
readonly contextTransferReceipt?: ContextTransferReceipt;
|
|
@@ -1358,23 +1378,12 @@ export interface AgentEnvironment {
|
|
|
1358
1378
|
readonly proxySecretReceipt?: ProxySecretReceipt;
|
|
1359
1379
|
/** API-verified effective parent pins read from current custody. */
|
|
1360
1380
|
readonly proxySecretParents?: ProxySecretParents;
|
|
1361
|
-
/**
|
|
1362
|
-
* Detached metadata returned by the provider.
|
|
1363
|
-
* It can contain caller-authored annotations and is not authorization evidence.
|
|
1364
|
-
*/
|
|
1381
|
+
/** Detached provider metadata can include caller annotations; it is not authorization evidence. */
|
|
1365
1382
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1366
|
-
/**
|
|
1367
|
-
*
|
|
1368
|
-
*
|
|
1369
|
-
*
|
|
1370
|
-
* A capability the connected deployment decides is environment-scoped: one
|
|
1371
|
-
* provider reaches deployments of different ages, so
|
|
1372
|
-
* {@link AgentEnvironmentProvider.capabilities} can only state what holds
|
|
1373
|
-
* before an environment exists. A provider that measures a capability per
|
|
1374
|
-
* environment publishes the measured answer here, and the operations this
|
|
1375
|
-
* environment exposes match it exactly. Absent when the provider document
|
|
1376
|
-
* already describes every environment it creates.
|
|
1377
|
-
*/
|
|
1383
|
+
/** This deployment's capability document; exposed operations match it.
|
|
1384
|
+
* Provider capabilities describe what is known before create; deployments
|
|
1385
|
+
* reached by one provider can differ in age. Absent when provider capabilities
|
|
1386
|
+
* already describe every environment it creates. */
|
|
1378
1387
|
readonly capabilities?: AgentEnvironmentCapabilities;
|
|
1379
1388
|
status(options?: {
|
|
1380
1389
|
signal?: AbortSignal;
|
|
@@ -1693,15 +1702,15 @@ export declare const AgentEnvironmentCapabilitiesSchema: z.ZodObject<{
|
|
|
1693
1702
|
confidential: z.ZodBoolean;
|
|
1694
1703
|
exactProcess: z.ZodOptional<z.ZodObject<{
|
|
1695
1704
|
egress: z.ZodArray<z.ZodEnum<{
|
|
1696
|
-
strict: "strict";
|
|
1697
1705
|
blocked: "blocked";
|
|
1706
|
+
strict: "strict";
|
|
1698
1707
|
}>>;
|
|
1699
1708
|
}, z.core.$strict>>;
|
|
1700
1709
|
create: z.ZodOptional<z.ZodObject<{
|
|
1701
1710
|
egress: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
1702
|
-
open: "open";
|
|
1703
|
-
strict: "strict";
|
|
1704
1711
|
blocked: "blocked";
|
|
1712
|
+
strict: "strict";
|
|
1713
|
+
open: "open";
|
|
1705
1714
|
}>>>;
|
|
1706
1715
|
durableIdempotency: z.ZodOptional<z.ZodBoolean>;
|
|
1707
1716
|
billingOwner: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -1763,18 +1772,18 @@ export declare const AgentEnvironmentCapabilitiesSchema: z.ZodObject<{
|
|
|
1763
1772
|
}, z.core.$strict>;
|
|
1764
1773
|
export interface CreateAgentEnvironmentInput extends AgentEnvironmentLifetime {
|
|
1765
1774
|
profile: AgentProfileRef;
|
|
1766
|
-
/**
|
|
1767
|
-
*
|
|
1768
|
-
* Providers must refuse unsupported attachments and authored MCP alias collisions.
|
|
1769
|
-
* Credentials are sensitive transport input; never include them in receipts or logs.
|
|
1770
|
-
* Attachments participate in keyed create identity and cannot be refreshed by replay.
|
|
1771
|
-
*/
|
|
1775
|
+
/** Runtime-owned attachments participate in keyed identity, not profile identity, and cannot refresh by replay.
|
|
1776
|
+
* Refuse unsupported attachments or MCP alias collisions; never log their credentials. */
|
|
1772
1777
|
runtimeAttachments?: AgentRuntimeAttachments;
|
|
1773
1778
|
/** Exact caller-owned id required by an accepted destination contract. */
|
|
1774
1779
|
requestedId?: string;
|
|
1775
1780
|
/** Agent backend inside the provider, for example "opencode" or "codex". */
|
|
1776
1781
|
backend?: string;
|
|
1777
1782
|
workspace?: WorkspaceRequest;
|
|
1783
|
+
/** Paths the platform seals with the stopped generation before retirement. */
|
|
1784
|
+
retain?: {
|
|
1785
|
+
paths: readonly string[];
|
|
1786
|
+
};
|
|
1778
1787
|
resources?: ResourceRequest;
|
|
1779
1788
|
env?: Record<string, string>;
|
|
1780
1789
|
secrets?: (string | {
|
|
@@ -1790,76 +1799,22 @@ export interface CreateAgentEnvironmentInput extends AgentEnvironmentLifetime {
|
|
|
1790
1799
|
proxySecrets?: readonly ProxySecretBinding[];
|
|
1791
1800
|
/** Host-only total destination-to-parent selection; null means explicit independent root. */
|
|
1792
1801
|
proxySecretParents?: ProxySecretParents;
|
|
1793
|
-
/**
|
|
1794
|
-
*
|
|
1795
|
-
*
|
|
1796
|
-
* When absent the provider applies its own default. That default can be a strict allowlist,
|
|
1797
|
-
* and a model endpoint the environment must reach is then refused inside the environment as an
|
|
1798
|
-
* authorization error that names no policy. Declare the policy whenever the destinations the
|
|
1799
|
-
* environment needs are known.
|
|
1800
|
-
*
|
|
1801
|
-
* A provider that cannot satisfy the requested mode must fail the create rather than weaken or
|
|
1802
|
-
* widen the policy. {@link AgentEnvironmentCapabilities.create} names the modes it accepts.
|
|
1803
|
-
*/
|
|
1802
|
+
/** Outbound network policy. Omission uses the provider default, which may be a strict allowlist.
|
|
1803
|
+
* Declare known required destinations; providers must refuse unsupported modes instead of widening
|
|
1804
|
+
* or weakening them. create capabilities name the accepted modes. */
|
|
1804
1805
|
egress?: AgentEnvironmentEgressPolicy;
|
|
1805
|
-
/**
|
|
1806
|
-
*
|
|
1807
|
-
*
|
|
1808
|
-
* A trusted first-party service acting for an authenticated user sets it. The provider honors
|
|
1809
|
-
* it only for a caller its platform has authorized to bill that account, and rejects the create
|
|
1810
|
-
* otherwise. It never grants a caller permission to charge an arbitrary account.
|
|
1811
|
-
*/
|
|
1806
|
+
/** Platform account funding managed model usage. Only a trusted service authorized to bill
|
|
1807
|
+
* that authenticated user's account may set it; other creates are rejected. */
|
|
1812
1808
|
billingOwner?: string;
|
|
1813
1809
|
metadata?: Record<string, unknown>;
|
|
1814
1810
|
name?: string;
|
|
1815
|
-
/**
|
|
1816
|
-
*
|
|
1817
|
-
*
|
|
1818
|
-
* When present, the provider must use this key as one idempotent operation:
|
|
1819
|
-
* the same key with canonically equal create input must return or reconstruct
|
|
1820
|
-
* the same environment, while a different input must be rejected.
|
|
1821
|
-
*/
|
|
1811
|
+
/** Idempotent create identity: the same key with equal canonical input reconstructs the same
|
|
1812
|
+
* environment; different input under that key is refused. */
|
|
1822
1813
|
idempotencyKey?: string;
|
|
1823
1814
|
signal?: AbortSignal;
|
|
1824
1815
|
providerOptions?: Record<string, unknown>;
|
|
1825
1816
|
}
|
|
1826
|
-
|
|
1827
|
-
* Compute the canonical identity of a generic environment create request.
|
|
1828
|
-
*
|
|
1829
|
-
* The operation key names the request and the abort signal controls one
|
|
1830
|
-
* attempt, so neither belongs in the input identity. Every other field is
|
|
1831
|
-
* canonicalized with the shared RFC 8785 JSON representation.
|
|
1832
|
-
* A keyed create therefore accepts only canonical JSON material.
|
|
1833
|
-
* Unkeyed creates can retain opaque provider-native mapper values.
|
|
1834
|
-
* @internal
|
|
1835
|
-
*/
|
|
1836
|
-
export declare function agentEnvironmentCreateInputDigest(input: CreateAgentEnvironmentInput): Sha256Digest;
|
|
1837
|
-
/** @internal State held by one provider adapter for keyed create retries. */
|
|
1838
|
-
export interface AgentEnvironmentCreateIdempotencyRecord<T> {
|
|
1839
|
-
readonly digest: Sha256Digest;
|
|
1840
|
-
readonly pending: Promise<T>;
|
|
1841
|
-
environment?: T;
|
|
1842
|
-
}
|
|
1843
|
-
/**
|
|
1844
|
-
* Apply the generic create contract to one provider adapter's keyed requests.
|
|
1845
|
-
*
|
|
1846
|
-
* The provider's backing service remains responsible for retaining the key
|
|
1847
|
-
* across adapter reconstruction. This helper coalesces concurrent retries and
|
|
1848
|
-
* rejects collisions before the provider performs another create effect.
|
|
1849
|
-
*
|
|
1850
|
-
* The call that runs `create` receives the environment the provider built,
|
|
1851
|
-
* with the creation verdict the provider could prove. Every same-key call
|
|
1852
|
-
* after it, including one that awaited the same pending create, receives
|
|
1853
|
-
* {@link replayedAgentEnvironmentView} of that environment.
|
|
1854
|
-
*
|
|
1855
|
-
* A keyed create callback receives one immutable canonical JSON snapshot.
|
|
1856
|
-
* Its digest and provider therefore read identical request bytes even when
|
|
1857
|
-
* the caller mutates its original object after this function returns.
|
|
1858
|
-
* An unkeyed create retains its original input so opaque provider-native
|
|
1859
|
-
* mapper values retain their public identity.
|
|
1860
|
-
* @internal
|
|
1861
|
-
*/
|
|
1862
|
-
export declare function createAgentEnvironmentWithIdempotency<T extends object>(records: Map<string, AgentEnvironmentCreateIdempotencyRecord<T>>, input: CreateAgentEnvironmentInput, create: (input: CreateAgentEnvironmentInput) => Promise<T>): Promise<T>;
|
|
1817
|
+
export { agentEnvironmentCreateInputDigest, createAgentEnvironmentWithIdempotency, type AgentEnvironmentCreateIdempotencyRecord } from "./environment-requests.js";
|
|
1863
1818
|
/** Reconstruct an existing environment; never allocates a replacement. */
|
|
1864
1819
|
export interface AgentEnvironmentGetOptions {
|
|
1865
1820
|
signal?: AbortSignal;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { AgentTurnFailureSchema } from "./execution-failure.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { ProxySecretCapabilitiesSchema, ProxySecretParentsSchema, isProxySecretParentsTotal, ProxySecretsSchema, ProxySecretUpdateControlsSchema } from "./proxy-secrets.js";
|
|
3
4
|
export { AgentRuntimeAttachmentsSchema } from "./runtime-attachments.js";
|
|
4
|
-
import { canonicalCandidateDigest, canonicalCandidateJson, } from "./agent-candidate-schema-common.js";
|
|
5
5
|
import { agentProfileSchema } from "./profile-schema.js";
|
|
6
6
|
import { TokenUsageSchema } from "./execution-types.js";
|
|
7
7
|
import { InteractionCapabilitiesSchema, RequestedInteractionsSchema } from "./interaction.js";
|
|
@@ -10,7 +10,6 @@ import { AgentExactRunControlRefSchema, AgentRunControlRefSchema, CanonicalStrea
|
|
|
10
10
|
import { AgentProfileCapabilitiesSchema } from "./environment-profile-capabilities.js";
|
|
11
11
|
import { boundedEventContentJsonSchema, boundedEventContentRecordSchema, boundedEventContentStringSchema, boundedIdentifierSchema, boundedJsonRecordSchema, boundedStringSchema, CONTRACT_MAX_ARRAY_LENGTH } from "./contract-limits.js";
|
|
12
12
|
import { InputPartSchema } from "./portable-context-shared.js";
|
|
13
|
-
import { deepFreeze } from "./deep-freeze.js";
|
|
14
13
|
export const AgentTurnInputSchema = z.strictObject({
|
|
15
14
|
profile: agentProfileSchema.optional(),
|
|
16
15
|
// A prompt is what the agent is asked to do, so it is CONTENT: its size is set by the work,
|
|
@@ -54,6 +53,7 @@ export const AgentTurnResultSchema = z.strictObject({
|
|
|
54
53
|
text: boundedEventContentStringSchema,
|
|
55
54
|
success: z.boolean(),
|
|
56
55
|
error: boundedStringSchema.optional(),
|
|
56
|
+
failure: AgentTurnFailureSchema.optional(),
|
|
57
57
|
sessionId: boundedIdentifierSchema.optional(),
|
|
58
58
|
usage: TokenUsageSchema.optional(),
|
|
59
59
|
metadata: boundedJsonRecordSchema.optional(),
|
|
@@ -436,96 +436,7 @@ export const AgentEnvironmentCapabilitiesSchema = z
|
|
|
436
436
|
});
|
|
437
437
|
}
|
|
438
438
|
});
|
|
439
|
-
|
|
440
|
-
* Compute the canonical identity of a generic environment create request.
|
|
441
|
-
*
|
|
442
|
-
* The operation key names the request and the abort signal controls one
|
|
443
|
-
* attempt, so neither belongs in the input identity. Every other field is
|
|
444
|
-
* canonicalized with the shared RFC 8785 JSON representation.
|
|
445
|
-
* A keyed create therefore accepts only canonical JSON material.
|
|
446
|
-
* Unkeyed creates can retain opaque provider-native mapper values.
|
|
447
|
-
* @internal
|
|
448
|
-
*/
|
|
449
|
-
export function agentEnvironmentCreateInputDigest(input) {
|
|
450
|
-
const { idempotencyKey: _idempotencyKey, signal: _signal, ...material } = input;
|
|
451
|
-
return canonicalCandidateDigest({
|
|
452
|
-
kind: "agent-environment-create.v1",
|
|
453
|
-
input: material,
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Return the per-call view of an environment that a same-key create replayed.
|
|
458
|
-
*
|
|
459
|
-
* The view shares every member of the environment, so operations act on the
|
|
460
|
-
* one environment, and it states `creation: "replayed"` because this call
|
|
461
|
-
* provisioned nothing. The copy is shallow, so the environment must be a plain
|
|
462
|
-
* object whose members do not read `this`; a class instance loses its
|
|
463
|
-
* prototype members in a copy and is rejected.
|
|
464
|
-
* @internal
|
|
465
|
-
*/
|
|
466
|
-
function replayedAgentEnvironmentView(environment) {
|
|
467
|
-
const prototype = Object.getPrototypeOf(environment);
|
|
468
|
-
if (prototype !== Object.prototype && prototype !== null) {
|
|
469
|
-
throw new Error("a replayed agent environment view requires a plain object environment");
|
|
470
|
-
}
|
|
471
|
-
return { ...environment, creation: "replayed" };
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* Apply the generic create contract to one provider adapter's keyed requests.
|
|
475
|
-
*
|
|
476
|
-
* The provider's backing service remains responsible for retaining the key
|
|
477
|
-
* across adapter reconstruction. This helper coalesces concurrent retries and
|
|
478
|
-
* rejects collisions before the provider performs another create effect.
|
|
479
|
-
*
|
|
480
|
-
* The call that runs `create` receives the environment the provider built,
|
|
481
|
-
* with the creation verdict the provider could prove. Every same-key call
|
|
482
|
-
* after it, including one that awaited the same pending create, receives
|
|
483
|
-
* {@link replayedAgentEnvironmentView} of that environment.
|
|
484
|
-
*
|
|
485
|
-
* A keyed create callback receives one immutable canonical JSON snapshot.
|
|
486
|
-
* Its digest and provider therefore read identical request bytes even when
|
|
487
|
-
* the caller mutates its original object after this function returns.
|
|
488
|
-
* An unkeyed create retains its original input so opaque provider-native
|
|
489
|
-
* mapper values retain their public identity.
|
|
490
|
-
* @internal
|
|
491
|
-
*/
|
|
492
|
-
export async function createAgentEnvironmentWithIdempotency(records, input, create) {
|
|
493
|
-
const { idempotencyKey: key, signal, ...material } = input;
|
|
494
|
-
signal?.throwIfAborted();
|
|
495
|
-
if (key === undefined)
|
|
496
|
-
return create(input);
|
|
497
|
-
const snapshot = deepFreeze(JSON.parse(canonicalCandidateJson(material)));
|
|
498
|
-
const acceptedInput = Object.freeze({
|
|
499
|
-
...snapshot,
|
|
500
|
-
idempotencyKey: key,
|
|
501
|
-
...(signal === undefined ? {} : { signal }),
|
|
502
|
-
});
|
|
503
|
-
const digest = agentEnvironmentCreateInputDigest(acceptedInput);
|
|
504
|
-
const existing = records.get(key);
|
|
505
|
-
if (existing !== undefined) {
|
|
506
|
-
if (existing.digest !== digest) {
|
|
507
|
-
throw new Error("agent environment create idempotency key conflicts with a different create input");
|
|
508
|
-
}
|
|
509
|
-
return replayedAgentEnvironmentView(existing.environment ?? (await existing.pending));
|
|
510
|
-
}
|
|
511
|
-
const pending = Promise.resolve().then(() => create(acceptedInput));
|
|
512
|
-
const record = {
|
|
513
|
-
digest,
|
|
514
|
-
pending,
|
|
515
|
-
};
|
|
516
|
-
records.set(key, record);
|
|
517
|
-
try {
|
|
518
|
-
const environment = await pending;
|
|
519
|
-
if (records.get(key) === record)
|
|
520
|
-
record.environment = environment;
|
|
521
|
-
return environment;
|
|
522
|
-
}
|
|
523
|
-
catch (error) {
|
|
524
|
-
if (records.get(key) === record)
|
|
525
|
-
records.delete(key);
|
|
526
|
-
throw error;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
439
|
+
export { agentEnvironmentCreateInputDigest, createAgentEnvironmentWithIdempotency } from "./environment-requests.js";
|
|
529
440
|
// Keep the existing parser strict: published providers that import it must not silently
|
|
530
441
|
// accept readOnly and then perform their ordinary reconnect side effects.
|
|
531
442
|
const environmentGetSignalSchema = z.custom().optional();
|
|
@@ -22,3 +22,16 @@ export declare class AgentExecutionError extends Error {
|
|
|
22
22
|
readonly receipt: AgentExecutionFailureReceipt;
|
|
23
23
|
constructor(message: string, receipt: AgentExecutionFailureReceipt, options?: ErrorOptions);
|
|
24
24
|
}
|
|
25
|
+
/** Stable producer-owned turn classification, retained independently of its diagnostic text. */
|
|
26
|
+
export declare const AgentTurnFailureSchema: z.ZodObject<{
|
|
27
|
+
kind: z.ZodEnum<{
|
|
28
|
+
capacity: "capacity";
|
|
29
|
+
caller: "caller";
|
|
30
|
+
infra: "infra";
|
|
31
|
+
work: "work";
|
|
32
|
+
}>;
|
|
33
|
+
code: z.ZodString;
|
|
34
|
+
resetAt: z.ZodOptional<z.ZodISODateTime>;
|
|
35
|
+
retryAfterMs: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
}, z.core.$strict>;
|
|
37
|
+
export type AgentTurnFailure = z.infer<typeof AgentTurnFailureSchema>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { boundedIdentifierSchema } from "./contract-limits.js";
|
|
2
3
|
import { deepFreeze } from "./deep-freeze.js";
|
|
3
4
|
import { TokenUsageSchema } from "./execution-types.js";
|
|
4
5
|
export const AgentExecutionFailureReceiptSchema = z.strictObject({
|
|
@@ -18,3 +19,10 @@ export class AgentExecutionError extends Error {
|
|
|
18
19
|
this.receipt = deepFreeze(AgentExecutionFailureReceiptSchema.parse(receipt));
|
|
19
20
|
}
|
|
20
21
|
}
|
|
22
|
+
/** Stable producer-owned turn classification, retained independently of its diagnostic text. */
|
|
23
|
+
export const AgentTurnFailureSchema = z.strictObject({
|
|
24
|
+
kind: z.enum(["capacity", "caller", "infra", "work"]),
|
|
25
|
+
code: boundedIdentifierSchema,
|
|
26
|
+
resetAt: z.iso.datetime().optional(),
|
|
27
|
+
retryAfterMs: z.number().int().nonnegative().safe().optional(),
|
|
28
|
+
});
|
|
@@ -120,14 +120,7 @@ export interface ModelReasoningCapability {
|
|
|
120
120
|
* lower ceiling caps the list there. Pass `model` from your catalog; omit it for the harness-only set.
|
|
121
121
|
*/
|
|
122
122
|
export declare function reasoningEffortsFor(harness: HarnessType, model?: ModelReasoningCapability | null): readonly ReasoningEffort[];
|
|
123
|
-
/**
|
|
124
|
-
* The native control token a harness applies for one canonical effort, or `null` when it applies
|
|
125
|
-
* none. `effort: null` (nothing requested) is always `null`.
|
|
126
|
-
*
|
|
127
|
-
* One owner for both sides of the check: the adapter that builds the harness argv and the caller
|
|
128
|
-
* that verifies the receipt read this function, so a CLI that renames a rung moves both at once
|
|
129
|
-
* instead of turning into a refused run.
|
|
130
|
-
*/
|
|
123
|
+
/** Native token shared by argv builders and receipt verification; null means no control. */
|
|
131
124
|
export declare function nativeReasoningControl(harness: HarnessType, effort: ReasoningEffort | null, model?: string): string | null;
|
|
132
125
|
/** Whether the harness's runner honors a per-turn MODEL override (vs. picking the model itself). */
|
|
133
126
|
export declare function harnessHonorsModel(harness: HarnessType): boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { REASONING_EFFORTS, } from "./agent-profile.js";
|
|
2
2
|
import { resolveHarnessType } from "./harness.js";
|
|
3
|
+
import { findProfileKbModel } from "./profile-kb/models.js";
|
|
3
4
|
/** Canonical harness/model, effort and prompt controls. Model-specific capability comes from the serving catalog. */
|
|
4
5
|
/** low → high. `none` = thinking off; `ultracode` = max (claude-code mode). */
|
|
5
6
|
export const reasoningLadder = REASONING_EFFORTS;
|
|
@@ -262,12 +263,7 @@ export function reasoningEffortsFor(harness, model) {
|
|
|
262
263
|
}
|
|
263
264
|
// ── Native reasoning control (the exact token the harness process receives) ───
|
|
264
265
|
/**
|
|
265
|
-
*
|
|
266
|
-
* native reasoning control for that request. This is the value a materialization receipt carries
|
|
267
|
-
* as `reasoningEffort.applied`, so a caller can check that the effort it asked for reached the
|
|
268
|
-
* process instead of trusting an echo of its own request.
|
|
269
|
-
*
|
|
270
|
-
* Read from the argv builders that actually spawn each CLI, not from help text:
|
|
266
|
+
* CLI controls recorded as reasoningEffort.applied in materialization receipts:
|
|
271
267
|
* - claude-code — `--effort <value>`; it cannot express `none` or `minimal`, so both clamp to
|
|
272
268
|
* `low`, and `ultracode` becomes its ceiling `max`.
|
|
273
269
|
* - codex — `-c model_reasoning_effort="<value>"`; it takes the canonical rungs directly and
|
|
@@ -276,16 +272,10 @@ export function reasoningEffortsFor(harness, model) {
|
|
|
276
272
|
* `max` (pi 1.4.0 `cli/args.js`, the prime fork's `cli/args.ts`, openclaw `agent --help`).
|
|
277
273
|
* - kimi-code — the control is the FLAG itself, `--thinking` or `--no-thinking`, because kimi's
|
|
278
274
|
* thinking switch is binary. `medium` is its default and passes no flag at all.
|
|
279
|
-
* - opencode — `--variant <value
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* answers `max` with 400). Pass `model` so this rung resolves; without it `xhigh` is sent.
|
|
284
|
-
*
|
|
285
|
-
* A harness with no entry applies NO native control: either it derives thinking from the model
|
|
286
|
-
* (gemini's `--thinking-budget`) or it plumbs no thinking flag at all (see
|
|
287
|
-
* {@link harnessHonorsEffort}). Both answer `null`, which is what their receipts carry — so an
|
|
288
|
-
* unknown harness is never asserted to have applied a control it cannot apply.
|
|
275
|
+
* - opencode — `--variant <value>`; `none` omits the flag. The sourced model KB owns native
|
|
276
|
+
* effort translations (Flash uses low/high/max). Otherwise `ultracode` becomes `max` for GLM
|
|
277
|
+
* and `xhigh` for other/unknown models; other rungs pass through.
|
|
278
|
+
* Unlisted harnesses apply no native control (see {@link harnessHonorsEffort}).
|
|
289
279
|
*/
|
|
290
280
|
const thinkingRung = (effort) => {
|
|
291
281
|
if (effort === "none")
|
|
@@ -312,19 +302,15 @@ const harnessNativeReasoningControl = {
|
|
|
312
302
|
opencode: (effort, model) => {
|
|
313
303
|
if (effort === "none")
|
|
314
304
|
return null;
|
|
305
|
+
const native = findProfileKbModel(model)?.nativeEfforts?.[effort];
|
|
306
|
+
if (native !== undefined)
|
|
307
|
+
return native;
|
|
315
308
|
if (effort !== "ultracode")
|
|
316
309
|
return effort;
|
|
317
310
|
return /(?:^|\/)glm-/iu.test(model ?? "") ? "max" : "xhigh";
|
|
318
311
|
},
|
|
319
312
|
};
|
|
320
|
-
/**
|
|
321
|
-
* The native control token a harness applies for one canonical effort, or `null` when it applies
|
|
322
|
-
* none. `effort: null` (nothing requested) is always `null`.
|
|
323
|
-
*
|
|
324
|
-
* One owner for both sides of the check: the adapter that builds the harness argv and the caller
|
|
325
|
-
* that verifies the receipt read this function, so a CLI that renames a rung moves both at once
|
|
326
|
-
* instead of turning into a refused run.
|
|
327
|
-
*/
|
|
313
|
+
/** Native token shared by argv builders and receipt verification; null means no control. */
|
|
328
314
|
export function nativeReasoningControl(harness, effort, model) {
|
|
329
315
|
if (effort === null)
|
|
330
316
|
return null;
|
|
@@ -9,18 +9,16 @@
|
|
|
9
9
|
import { composeAgentProfileGuidance, type AgentProfile } from "../agent-profile.js";
|
|
10
10
|
import type { HarnessType } from "../harness.js";
|
|
11
11
|
import { profileKbHarnesses } from "./harnesses.js";
|
|
12
|
-
import { profileKbModels } from "./models.js";
|
|
12
|
+
import { profileKbModels, profileKbNamesModel } from "./models.js";
|
|
13
13
|
import { profileKbDiscrepancies, profileKbLearnings } from "./records.js";
|
|
14
14
|
export type * from "./types.js";
|
|
15
15
|
export type { AgentProfileGuidanceBlock, AgentProfileGuidanceChannel, AgentProfileGuidanceOptions, } from "../agent-profile.js";
|
|
16
|
-
export { composeAgentProfileGuidance, profileKbDiscrepancies, profileKbHarnesses, profileKbLearnings, profileKbModels, };
|
|
16
|
+
export { composeAgentProfileGuidance, profileKbDiscrepancies, profileKbHarnesses, profileKbLearnings, profileKbModels, profileKbNamesModel, };
|
|
17
17
|
/**
|
|
18
18
|
* The guidance block sources the knowledge base owns. {@link withProfileKb}
|
|
19
19
|
* replaces blocks from these sources and keeps blocks any other layer added.
|
|
20
20
|
*/
|
|
21
21
|
export declare const PROFILE_KB_SOURCES: readonly ["harness", "model", "learning"];
|
|
22
|
-
/** Whether the knowledge base lists this exact spelling: a model id or one of its aliases, such as `zai-coding-plan/glm-5.3`. */
|
|
23
|
-
export declare const profileKbNamesModel: (name: string) => boolean;
|
|
24
22
|
/** Which harness and model to compose guidance for. */
|
|
25
23
|
export interface ProfileKbSelection {
|
|
26
24
|
harness?: HarnessType | string;
|
package/dist/profile-kb/index.js
CHANGED
|
@@ -10,9 +10,9 @@ import { composeAgentProfileGuidance, } from "../agent-profile.js";
|
|
|
10
10
|
import { deepFreeze } from "../deep-freeze.js";
|
|
11
11
|
import { harnessSystemPromptIntents } from "../harness-capabilities.js";
|
|
12
12
|
import { profileKbHarnesses } from "./harnesses.js";
|
|
13
|
-
import { profileKbModels } from "./models.js";
|
|
13
|
+
import { findProfileKbModel, profileKbModels, profileKbNamesModel } from "./models.js";
|
|
14
14
|
import { profileKbDiscrepancies, profileKbLearnings } from "./records.js";
|
|
15
|
-
export { composeAgentProfileGuidance, profileKbDiscrepancies, profileKbHarnesses, profileKbLearnings, profileKbModels, };
|
|
15
|
+
export { composeAgentProfileGuidance, profileKbDiscrepancies, profileKbHarnesses, profileKbLearnings, profileKbModels, profileKbNamesModel, };
|
|
16
16
|
/**
|
|
17
17
|
* The guidance block sources the knowledge base owns. {@link withProfileKb}
|
|
18
18
|
* replaces blocks from these sources and keeps blocks any other layer added.
|
|
@@ -25,47 +25,10 @@ export const PROFILE_KB_SOURCES = ["harness", "model", "learning"];
|
|
|
25
25
|
* types stay as they were published.
|
|
26
26
|
*/
|
|
27
27
|
const harnessSnapshot = deepFreeze(structuredClone(profileKbHarnesses));
|
|
28
|
-
const modelSnapshot = deepFreeze(structuredClone(profileKbModels));
|
|
29
28
|
const learningSnapshot = deepFreeze(structuredClone(profileKbLearnings));
|
|
30
29
|
function harnessPosition(harness) {
|
|
31
30
|
return harnessSnapshot.findIndex((entry) => entry.id === harness);
|
|
32
31
|
}
|
|
33
|
-
const modelIndex = (() => {
|
|
34
|
-
const index = new Map();
|
|
35
|
-
modelSnapshot.forEach((model, position) => {
|
|
36
|
-
for (const name of [model.id, ...model.aliases]) {
|
|
37
|
-
const key = name.toLowerCase();
|
|
38
|
-
if (index.has(key)) {
|
|
39
|
-
throw new Error(`profile-kb: model name ${name} is declared twice`);
|
|
40
|
-
}
|
|
41
|
-
index.set(key, position);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
return index;
|
|
45
|
-
})();
|
|
46
|
-
/**
|
|
47
|
-
* Try the name as given, then without each leading `provider/` or route
|
|
48
|
-
* segment, after dropping a trailing `:suffix`.
|
|
49
|
-
*/
|
|
50
|
-
function matchModelName(model, lookup) {
|
|
51
|
-
if (!model)
|
|
52
|
-
return undefined;
|
|
53
|
-
const colon = model.lastIndexOf(":");
|
|
54
|
-
let candidate = (colon > 0 ? model.slice(0, colon) : model)
|
|
55
|
-
.trim()
|
|
56
|
-
.toLowerCase();
|
|
57
|
-
for (;;) {
|
|
58
|
-
const found = lookup(candidate);
|
|
59
|
-
if (found !== undefined)
|
|
60
|
-
return found;
|
|
61
|
-
const slash = candidate.indexOf("/");
|
|
62
|
-
if (slash < 0)
|
|
63
|
-
return undefined;
|
|
64
|
-
candidate = candidate.slice(slash + 1);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/** Whether the knowledge base lists this exact spelling: a model id or one of its aliases, such as `zai-coding-plan/glm-5.3`. */
|
|
68
|
-
export const profileKbNamesModel = (name) => modelIndex.has(name.trim().toLowerCase());
|
|
69
32
|
function learningsFor(harness, model) {
|
|
70
33
|
return learningSnapshot.filter((learning) => {
|
|
71
34
|
const scope = learning.appliesTo;
|
|
@@ -89,7 +52,7 @@ function profileKbGuidance(selection) {
|
|
|
89
52
|
const harness = selection.harness
|
|
90
53
|
? harnessSnapshot[harnessPosition(selection.harness)]
|
|
91
54
|
: undefined;
|
|
92
|
-
const model =
|
|
55
|
+
const model = findProfileKbModel(selection.model);
|
|
93
56
|
const blocks = [];
|
|
94
57
|
if (harness && harness.prompt.length > 0) {
|
|
95
58
|
blocks.push({
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { ProfileKbModel } from "./types.js";
|
|
2
2
|
/** Source-backed facts and conditional advice. API controls never become agent instructions. */
|
|
3
3
|
export declare const profileKbModels: readonly ProfileKbModel[];
|
|
4
|
+
/** Match an id/alias, then strip leading route segments and a trailing :suffix. */
|
|
5
|
+
export declare function findProfileKbModel(model: string | undefined): ProfileKbModel | undefined;
|
|
6
|
+
/** Whether this exact spelling is a declared model id or alias. */
|
|
7
|
+
export declare const profileKbNamesModel: (name: string) => boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { deepFreeze } from "../deep-freeze.js";
|
|
1
2
|
import { claim, kbEntry } from "./entry.js";
|
|
2
3
|
const CHECKED = "2026-10-04";
|
|
3
4
|
const source = (url, locator) => ({
|
|
@@ -229,6 +230,14 @@ export const profileKbModels = [
|
|
|
229
230
|
vendor: "DeepSeek",
|
|
230
231
|
surfaces: ["api", "router", "opencode"],
|
|
231
232
|
aliases: ["deepseek-flash", "deepseek/deepseek-v4.1-flash", "opencode/deepseek-v4.1-flash-free"],
|
|
233
|
+
nativeEfforts: {
|
|
234
|
+
minimal: "low",
|
|
235
|
+
low: "low",
|
|
236
|
+
medium: "high",
|
|
237
|
+
high: "high",
|
|
238
|
+
xhigh: "high",
|
|
239
|
+
ultracode: "max",
|
|
240
|
+
},
|
|
232
241
|
claims: [
|
|
233
242
|
claim("DeepSeek API ID deepseek-flash denotes V4.1-Flash: 1M context, 384K output, vision and tools; non-thinking mode is available. Router naming is a separate contract.", deepseekModel),
|
|
234
243
|
claim("Thinking defaults on at high. Native efforts are low, high and max; minimal maps to low, medium/xhigh to high, and ultra to max. With tools, preserve all previous reasoning_content, including turns without tool calls.", deepseekThinking),
|
|
@@ -273,3 +282,38 @@ export const profileKbModels = [
|
|
|
273
282
|
],
|
|
274
283
|
}),
|
|
275
284
|
];
|
|
285
|
+
// Both guidance and native controls read this snapshot, never mutable exports.
|
|
286
|
+
const modelSnapshot = deepFreeze(structuredClone(profileKbModels));
|
|
287
|
+
const modelIndex = (() => {
|
|
288
|
+
const index = new Map();
|
|
289
|
+
for (const model of modelSnapshot) {
|
|
290
|
+
for (const name of [model.id, ...model.aliases]) {
|
|
291
|
+
const key = name.toLowerCase();
|
|
292
|
+
if (index.has(key)) {
|
|
293
|
+
throw new Error(`profile-kb: model name ${name} is declared twice`);
|
|
294
|
+
}
|
|
295
|
+
index.set(key, model);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return index;
|
|
299
|
+
})();
|
|
300
|
+
/** Match an id/alias, then strip leading route segments and a trailing :suffix. */
|
|
301
|
+
export function findProfileKbModel(model) {
|
|
302
|
+
if (!model)
|
|
303
|
+
return undefined;
|
|
304
|
+
const colon = model.lastIndexOf(":");
|
|
305
|
+
let candidate = (colon > 0 ? model.slice(0, colon) : model)
|
|
306
|
+
.trim()
|
|
307
|
+
.toLowerCase();
|
|
308
|
+
for (;;) {
|
|
309
|
+
const found = modelIndex.get(candidate);
|
|
310
|
+
if (found !== undefined)
|
|
311
|
+
return found;
|
|
312
|
+
const slash = candidate.indexOf("/");
|
|
313
|
+
if (slash < 0)
|
|
314
|
+
return undefined;
|
|
315
|
+
candidate = candidate.slice(slash + 1);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/** Whether this exact spelling is a declared model id or alias. */
|
|
319
|
+
export const profileKbNamesModel = (name) => modelIndex.has(name.trim().toLowerCase());
|
|
@@ -55,6 +55,8 @@ export interface ProfileKbModel {
|
|
|
55
55
|
aliases: string[];
|
|
56
56
|
/** Documented API default mapped onto the portable scale (ultracode means max); harness defaults can differ. */
|
|
57
57
|
defaultEffort?: ReasoningEffort;
|
|
58
|
+
/** Documented native tokens for the portable thinking rungs; none stays off. */
|
|
59
|
+
nativeEfforts?: Readonly<Record<Exclude<ReasoningEffort, "none">, string>>;
|
|
58
60
|
sources: ProfileKbSource[];
|
|
59
61
|
prompt: string[];
|
|
60
62
|
operator: string[];
|