@chengchenccc/agent-contract 0.1.1-rc.1
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/ask-question.d.ts +58 -0
- package/dist/ask-question.d.ts.map +1 -0
- package/dist/ask-question.js +2 -0
- package/dist/backend.d.ts +49 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +1 -0
- package/dist/cli-consume.d.ts +5 -0
- package/dist/cli-consume.d.ts.map +1 -0
- package/dist/cli-consume.js +11 -0
- package/dist/debug.d.ts +2 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +11 -0
- package/dist/env.d.ts +4 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +33 -0
- package/dist/event.d.ts +80 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +1 -0
- package/dist/history.d.ts +41 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/kinds.d.ts +14 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/kinds.js +12 -0
- package/dist/model.d.ts +40 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +1 -0
- package/dist/redact.d.ts +5 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +31 -0
- package/dist/run.d.ts +110 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +1 -0
- package/package.json +32 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** ask_question tool protocol (oh-my-pi style questions; select + text kinds). */
|
|
2
|
+
export interface AskQuestionOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
preview?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface AskQuestionValidation {
|
|
9
|
+
/** default true */
|
|
10
|
+
required?: boolean;
|
|
11
|
+
/** text only */
|
|
12
|
+
minLength?: number;
|
|
13
|
+
/** text only */
|
|
14
|
+
maxLength?: number;
|
|
15
|
+
/** multi select only */
|
|
16
|
+
minSelections?: number;
|
|
17
|
+
/** multi select only */
|
|
18
|
+
maxSelections?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface AskQuestionItem {
|
|
21
|
+
id: string;
|
|
22
|
+
/** "select" = options picker; "text" = free input. Default "select". */
|
|
23
|
+
kind: "select" | "text";
|
|
24
|
+
question: string;
|
|
25
|
+
/** grouping header shown above the question */
|
|
26
|
+
header?: string;
|
|
27
|
+
multi?: boolean;
|
|
28
|
+
options?: AskQuestionOption[];
|
|
29
|
+
/** option.value to badge as (Recommended) */
|
|
30
|
+
recommended?: string;
|
|
31
|
+
/** show an "Other (type your own)" free-text row */
|
|
32
|
+
allowOther?: boolean;
|
|
33
|
+
/** offer "Chat about this" instead of answering the form */
|
|
34
|
+
allowChat?: boolean;
|
|
35
|
+
placeholder?: string;
|
|
36
|
+
/** textarea instead of single-line input */
|
|
37
|
+
multiline?: boolean;
|
|
38
|
+
validation?: AskQuestionValidation;
|
|
39
|
+
}
|
|
40
|
+
export interface AskQuestionInput {
|
|
41
|
+
questions: AskQuestionItem[];
|
|
42
|
+
}
|
|
43
|
+
export interface AskQuestionAnswerItem {
|
|
44
|
+
id: string;
|
|
45
|
+
/** selected option values (select kind) */
|
|
46
|
+
selectedValues: string[];
|
|
47
|
+
/** free text (text kind, or the "Other" row on select kind) */
|
|
48
|
+
freeText?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface AskQuestionResult {
|
|
51
|
+
answers: AskQuestionAnswerItem[];
|
|
52
|
+
}
|
|
53
|
+
/** Structured message kept in the conversation after the user submits. */
|
|
54
|
+
export interface AskQuestionFilled {
|
|
55
|
+
kind: "ask_question_filled";
|
|
56
|
+
answers: AskQuestionAnswerItem[];
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=ask-question.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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Ac,EAAE,MAAM,EAAE,CAAC;IACzB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,qBAAqB,EAAE,CAAC;CAClC;AAED,0EAA0E;AAC1E,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,qBAAqB,CAAC;IAC5B,OAAO,EAAE,qBAAqB,EAAE,CAAC;CAClC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { BackendKind } from "./kinds.js";
|
|
2
|
+
import type { BackendCatalog } from "./model.js";
|
|
3
|
+
import type { BackendInputMessage, BackendRunInput, BackendRunSegment } from "./run.js";
|
|
4
|
+
/** One registered backend kind: the AgentBackend plus its model catalog.
|
|
5
|
+
* The registry is the Product Backend's single dispatch table; execution
|
|
6
|
+
* resolves `modelRef.backendKind` against it and reports a clear error for
|
|
7
|
+
* unknown/unregistered kinds. */
|
|
8
|
+
export interface BackendRegistryEntry {
|
|
9
|
+
readonly backend: AgentBackend<BackendKind>;
|
|
10
|
+
readonly catalog: BackendCatalog;
|
|
11
|
+
}
|
|
12
|
+
/** Partial: a deployment may omit kinds (e.g. pi not installed). */
|
|
13
|
+
export type BackendRegistry = Partial<Record<BackendKind, BackendRegistryEntry>>;
|
|
14
|
+
/** The only execution protocol Product Backend depends on. Run-centric: one
|
|
15
|
+
* non-steer input maps to exactly one `execute()` call, one loop, one
|
|
16
|
+
* `BackendRunOutcome`. There is no session lifecycle - `runId` is the only
|
|
17
|
+
* execution identity and every Run rebuilds its input from the full Product
|
|
18
|
+
* Context projection. `steer` injects into the CURRENT live Run only; `stop`
|
|
19
|
+
* terminates the target Run.
|
|
20
|
+
*
|
|
21
|
+
* `K` is the Backend's kind string (e.g. `"oma"`). It locks
|
|
22
|
+
* extension events to `backend.<K>.*` and constrains every input's model ref
|
|
23
|
+
* to the same `K`. */
|
|
24
|
+
export interface AgentBackend<K extends string = string> {
|
|
25
|
+
readonly kind: K;
|
|
26
|
+
/** Start a fresh Run: full history + input + run snapshot + workspace.
|
|
27
|
+
* The segment's outcome is the run's ONLY terminal result. Same runId +
|
|
28
|
+
* same payload is idempotent (replays the accepted result); same runId +
|
|
29
|
+
* different payload conflicts. */
|
|
30
|
+
execute(input: BackendRunInput<K>): Promise<BackendRunSegment<K>>;
|
|
31
|
+
/** Inject a steer input into the live Run `runId`. No new Run, no new
|
|
32
|
+
* outcome. Fails explicitly when the Run is not live - never silently
|
|
33
|
+
* converted into a normal input. */
|
|
34
|
+
steer(runId: string, input: BackendInputMessage): Promise<void>;
|
|
35
|
+
/** Resolve a pending HITL approval in the live Run `runId` (spec: approval
|
|
36
|
+
* pipeline). Optional: backends without an approval pipeline never create
|
|
37
|
+
* approval requests, so the Product can gate the endpoint on its
|
|
38
|
+
* presence. Fails explicitly when the Run is not live. */
|
|
39
|
+
resolveApproval?(runId: string, callId: string, decision: "allow" | "deny"): Promise<void>;
|
|
40
|
+
/** Request cancellation of the live Run `runId`. The segment's outcome
|
|
41
|
+
* still resolves (aborted). */
|
|
42
|
+
stop(runId: string): Promise<void>;
|
|
43
|
+
/** Shut down ALL children deterministically (Backend shutdown path):
|
|
44
|
+
* reject new executes, cancel queued spawns, abort accepted children,
|
|
45
|
+
* SIGTERM pre-acceptance children, SIGKILL after a bounded grace, and
|
|
46
|
+
* await every child's exit. Never blocks on a stuck acceptance. */
|
|
47
|
+
dispose(): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAExF;;;kCAGkC;AAClC,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC;IAC5C,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;CAClC;AAED,oEAAoE;AACpE,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC,CAAC;AAEjF;;;;;;;;;uBASuB;AACvB,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACrD,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAEjB;;;uCAGmC;IACnC,OAAO,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;IAElE;;yCAEqC;IACrC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhE;;;+DAG2D;IAC3D,eAAe,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3F;oCACgC;IAChC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnC;;;wEAGoE;IACpE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
|
package/dist/backend.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Shared CLI-backend consume guard: a rejected stdout-consume promise must
|
|
2
|
+
* never leave a Run unsettled (an eternally "running" branch). Every CLI
|
|
3
|
+
* adapter wraps its consume body with this and settles failed on error. */
|
|
4
|
+
export declare function guardedConsume(consume: () => Promise<void>, onError: (message: string) => void): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=cli-consume.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-consume.d.ts","sourceRoot":"","sources":["../src/cli-consume.ts"],"names":[],"mappings":"AAAA;;4EAE4E;AAC5E,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAC5B,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GACjC,OAAO,CAAC,IAAI,CAAC,CAMf"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Shared CLI-backend consume guard: a rejected stdout-consume promise must
|
|
2
|
+
* never leave a Run unsettled (an eternally "running" branch). Every CLI
|
|
3
|
+
* adapter wraps its consume body with this and settles failed on error. */
|
|
4
|
+
export async function guardedConsume(consume, onError) {
|
|
5
|
+
try {
|
|
6
|
+
await consume();
|
|
7
|
+
}
|
|
8
|
+
catch (err) {
|
|
9
|
+
onError(err instanceof Error ? err.message : String(err));
|
|
10
|
+
}
|
|
11
|
+
}
|
package/dist/debug.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAOA,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAG3D"}
|
package/dist/debug.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Minimal OMA_DEBUG=1 diagnostic logger. Writes one line per
|
|
2
|
+
* lifecycle milestone to stderr; no-op unless the env var is exactly "1".
|
|
3
|
+
* Never logs message bodies, tool inputs, prompts or secrets - only
|
|
4
|
+
* stage names, ids, counts and statuses. The child inherits the env, so
|
|
5
|
+
* the same switch lights up backend, adapter, child RPC and loop logs. */
|
|
6
|
+
const DEBUG_ENABLED = process.env.OMA_DEBUG === "1";
|
|
7
|
+
export function debugLog(tag, message) {
|
|
8
|
+
if (!DEBUG_ENABLED)
|
|
9
|
+
return;
|
|
10
|
+
process.stderr.write(`[${tag}] ${message}\n`);
|
|
11
|
+
}
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Build a child spawn env: a small allowlist of parent vars plus the
|
|
2
|
+
* caller's explicit overrides. `extra` wins on key collisions. */
|
|
3
|
+
export declare function childEnv(extra?: Readonly<Record<string, string | undefined>>): Record<string, string>;
|
|
4
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAmBA;mEACmE;AACnE,wBAAgB,QAAQ,CACtB,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GACnD,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUxB"}
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Parent env keys forwarded to spawned agent CLIs. Everything else in the
|
|
2
|
+
* parent environment (backend auth tokens, host secrets, daemon handles)
|
|
3
|
+
* must NOT reach an agent-controlled child. Per-run secrets ride in the
|
|
4
|
+
* `extra` argument and are never inherited. */
|
|
5
|
+
const FORWARDED_KEYS = [
|
|
6
|
+
"PATH",
|
|
7
|
+
"HOME",
|
|
8
|
+
"LANG",
|
|
9
|
+
"TZ",
|
|
10
|
+
// Provider credentials (the child resolves which providers have keys).
|
|
11
|
+
"ANTHROPIC_API_KEY",
|
|
12
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
13
|
+
"ANTHROPIC_BASE_URL",
|
|
14
|
+
"OPENAI_API_KEY",
|
|
15
|
+
"DEEPSEEK_API_KEY",
|
|
16
|
+
"GROQ_API_KEY",
|
|
17
|
+
"OPENROUTER_API_KEY",
|
|
18
|
+
];
|
|
19
|
+
/** Build a child spawn env: a small allowlist of parent vars plus the
|
|
20
|
+
* caller's explicit overrides. `extra` wins on key collisions. */
|
|
21
|
+
export function childEnv(extra) {
|
|
22
|
+
const env = {};
|
|
23
|
+
for (const key of FORWARDED_KEYS) {
|
|
24
|
+
const value = process.env[key];
|
|
25
|
+
if (value !== undefined)
|
|
26
|
+
env[key] = value;
|
|
27
|
+
}
|
|
28
|
+
for (const [key, value] of Object.entries(extra ?? {})) {
|
|
29
|
+
if (value !== undefined)
|
|
30
|
+
env[key] = value;
|
|
31
|
+
}
|
|
32
|
+
return env;
|
|
33
|
+
}
|
package/dist/event.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Unified token/cost statistics. Missing fields are allowed to be absent. */
|
|
2
|
+
export interface Usage {
|
|
3
|
+
readonly inputTokens?: number;
|
|
4
|
+
readonly outputTokens?: number;
|
|
5
|
+
readonly cacheReadTokens?: number;
|
|
6
|
+
readonly cacheWriteTokens?: number;
|
|
7
|
+
readonly costUsd?: number;
|
|
8
|
+
}
|
|
9
|
+
/** Stable core events observed by Product Backend. Backends map their native
|
|
10
|
+
* events onto this small set. Business state machines must never derive a
|
|
11
|
+
* terminal state from events - `BackendRunOutcome` is the only terminal
|
|
12
|
+
* authority. UI lifecycle observation uses the open-ended `status` event. */
|
|
13
|
+
export type CoreBackendEvent = {
|
|
14
|
+
readonly type: "text_delta";
|
|
15
|
+
readonly text: string;
|
|
16
|
+
} | {
|
|
17
|
+
readonly type: "thinking_delta";
|
|
18
|
+
readonly text: string;
|
|
19
|
+
} | {
|
|
20
|
+
readonly type: "product_tool_started";
|
|
21
|
+
readonly toolName: string;
|
|
22
|
+
readonly callId: string;
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: "product_tool_completed";
|
|
25
|
+
readonly toolName: string;
|
|
26
|
+
readonly callId: string;
|
|
27
|
+
readonly result?: Readonly<Record<string, unknown>>;
|
|
28
|
+
} | {
|
|
29
|
+
readonly type: "native_tool_started";
|
|
30
|
+
readonly toolName: string;
|
|
31
|
+
readonly callId: string;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "native_tool_completed";
|
|
34
|
+
readonly toolName: string;
|
|
35
|
+
readonly callId: string;
|
|
36
|
+
readonly result?: Readonly<Record<string, unknown>>;
|
|
37
|
+
} | {
|
|
38
|
+
readonly type: "pending_action";
|
|
39
|
+
readonly actionId: string;
|
|
40
|
+
} | {
|
|
41
|
+
readonly type: "status";
|
|
42
|
+
readonly status: string;
|
|
43
|
+
readonly error?: string;
|
|
44
|
+
} | {
|
|
45
|
+
readonly type: "workflow_started";
|
|
46
|
+
readonly workflowId: string;
|
|
47
|
+
readonly label: string;
|
|
48
|
+
readonly agentCount: number;
|
|
49
|
+
} | {
|
|
50
|
+
readonly type: "workflow_agent_started";
|
|
51
|
+
readonly workflowId: string;
|
|
52
|
+
readonly agentId: string;
|
|
53
|
+
readonly label: string;
|
|
54
|
+
} | {
|
|
55
|
+
readonly type: "workflow_agent_completed";
|
|
56
|
+
readonly workflowId: string;
|
|
57
|
+
readonly agentId: string;
|
|
58
|
+
readonly label: string;
|
|
59
|
+
readonly ok: boolean;
|
|
60
|
+
readonly error?: string;
|
|
61
|
+
readonly usage?: unknown;
|
|
62
|
+
} | {
|
|
63
|
+
readonly type: "workflow_completed";
|
|
64
|
+
readonly workflowId: string;
|
|
65
|
+
readonly ok: boolean;
|
|
66
|
+
readonly agentCount: number;
|
|
67
|
+
readonly totalTokens: number;
|
|
68
|
+
};
|
|
69
|
+
/** Opaque Backend-specific event. The kind segment must match the producing
|
|
70
|
+
* Backend's `backendKind`; the event segment is Backend-private. Usable for
|
|
71
|
+
* diagnostics or UI enhancement, never for product state. Parameterized by
|
|
72
|
+
* `K` so a Backend of kind `K` can only emit `backend.<K>.<event>`. */
|
|
73
|
+
export interface BackendExtensionEvent<K extends string> {
|
|
74
|
+
readonly type: `backend.${K}.${string}`;
|
|
75
|
+
readonly payload: Readonly<Record<string, unknown>>;
|
|
76
|
+
}
|
|
77
|
+
/** The full event union a Backend of kind `K` may emit. `K` defaults to
|
|
78
|
+
* `string` for the opaque (un-parameterized) consumer. */
|
|
79
|
+
export type BackendEvent<K extends string = string> = CoreBackendEvent | BackendExtensionEvent<K>;
|
|
80
|
+
//# sourceMappingURL=event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;8EAG8E;AAC9E,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACtD;IAAE,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7F;IACE,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAC;IACxC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACrD,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAA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MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEN;;;wEAGwE;AACxE,MAAM,WAAW,qBAAqB,CAAC,CAAC,SAAS,MAAM;IACrD,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,MAAM,EAAE,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACrD;AAED;2DAC2D;AAC3D,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,gBAAgB,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/event.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Message } from "@chengchenccc/message";
|
|
2
|
+
import type { BackendModelRef } from "./model.js";
|
|
3
|
+
/** A projected history entry. `productEntryId` is the stable Agent Context
|
|
4
|
+
* entry identity, retained so the Runtime can write it onto its appended
|
|
5
|
+
* entries and never persist the same canonical Message twice. It is not a
|
|
6
|
+
* Runtime message ID and must not be regenerated by the Runtime. */
|
|
7
|
+
export interface ProjectedHistoryItem {
|
|
8
|
+
readonly productEntryId: string;
|
|
9
|
+
readonly message: Message;
|
|
10
|
+
}
|
|
11
|
+
/** Runtime-accessible workspace and its permission boundary. */
|
|
12
|
+
export interface WorkspaceBinding {
|
|
13
|
+
readonly root: string;
|
|
14
|
+
readonly access: "read_only" | "read_write";
|
|
15
|
+
}
|
|
16
|
+
/** Frozen per-Run configuration. Fixed at Agent Run start; every `execute()`
|
|
17
|
+
* carries it so model and system prompt changes take effect on the next Run
|
|
18
|
+
* without any shared state. Product Tool definitions ride the workspace
|
|
19
|
+
* files (.oma/product-tools.json, ADR 0003 decision 6), not this snapshot.
|
|
20
|
+
* Parameterized by `K` so the model ref's backendKind is locked to the
|
|
21
|
+
* Backend's kind. */
|
|
22
|
+
export interface AgentRunSnapshot<K extends string = string> {
|
|
23
|
+
readonly runId: string;
|
|
24
|
+
readonly model: BackendModelRef<K>;
|
|
25
|
+
readonly systemPrompt?: string;
|
|
26
|
+
/** Skill pack roots (absolute dirs scanned for SKILL.md), frozen at Run
|
|
27
|
+
* creation. The Runtime loads them via the progressive skill plugin. */
|
|
28
|
+
readonly skillRoots?: readonly string[];
|
|
29
|
+
/** The branch's CLI session reference (ADR 0003 decision 6): an opaque
|
|
30
|
+
* pointer the oma resolves itself (its own native session
|
|
31
|
+
* storage). Absent = fresh session. The product stores only this
|
|
32
|
+
* reference — never manages the CLI's session files. */
|
|
33
|
+
readonly cliSessionRef?: string;
|
|
34
|
+
/** Frozen permission_mode (ask/auto/deny), mapped per backend at
|
|
35
|
+
* dispatch (ADR 0020 decision 7). */
|
|
36
|
+
readonly permissionMode?: "ask" | "auto" | "deny";
|
|
37
|
+
/** Optional workflow budget (tokens) frozen at Run creation. */
|
|
38
|
+
readonly workflowBudgetTokens?: number;
|
|
39
|
+
readonly configRevision: number;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;qEAGqE;AACrE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED,gEAAgE;AAChE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,YAAY,CAAC;CAC7C;AAED;;;;;sBAKsB;AACtB,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACzD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IACnC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B;6EACyE;IACzE,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC;;;6DAGyD;IACzD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC;0CACsC;IACtC,QAAQ,CAAC,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;IAClD,gEAAgE;IAChE,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC"}
|
package/dist/history.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type { AskQuestionAnswerItem, AskQuestionFilled, AskQuestionInput, AskQuestionItem, AskQuestionOption, AskQuestionResult, AskQuestionValidation, } from "./ask-question.js";
|
|
2
|
+
export type { AgentBackend, BackendRegistry, BackendRegistryEntry } from "./backend.js";
|
|
3
|
+
export { guardedConsume } from "./cli-consume.js";
|
|
4
|
+
export { debugLog } from "./debug.js";
|
|
5
|
+
export { childEnv } from "./env.js";
|
|
6
|
+
export type { BackendEvent, BackendExtensionEvent, CoreBackendEvent, Usage } from "./event.js";
|
|
7
|
+
export type { AgentRunSnapshot, ProjectedHistoryItem, WorkspaceBinding, } from "./history.js";
|
|
8
|
+
export type { BackendKind } from "./kinds.js";
|
|
9
|
+
export { BACKEND_KINDS, backendKindSchema } from "./kinds.js";
|
|
10
|
+
export type { BackendCatalog, BackendModel, BackendModelCatalog, BackendModelRef, } from "./model.js";
|
|
11
|
+
export { collectSecrets, redactText } from "./redact.js";
|
|
12
|
+
export type { BackendInputMessage, BackendRunInput, BackendRunOutcome, BackendRunSegment, PendingAction, PendingActionResponse, } from "./run.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC/F,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC9D,YAAY,EACV,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzD,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,qBAAqB,GACtB,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
package/dist/kinds.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** The full set of execution backends the Product Backend can dispatch to.
|
|
3
|
+
* Each kind has exactly one adapter package implementing `AgentBackend<K>`:
|
|
4
|
+
* - oma: 自家 child (apps/oh-my-agent --mode rpc)
|
|
5
|
+
* - claude_code: Claude Code CLI (--output-format stream-json)
|
|
6
|
+
* - pi: pi CLI (@earendil-works/pi-oma, -p --mode json)
|
|
7
|
+
* - omp: omp CLI (@oh-my-pi/pi-oma, -p --mode json)
|
|
8
|
+
*
|
|
9
|
+
* The wire contract in transport.ts accepts this union; a child enforces
|
|
10
|
+
* its own kind at runtime (see oma rpc-mode). */
|
|
11
|
+
export declare const BACKEND_KINDS: readonly ["oma", "claude_code", "pi", "omp"];
|
|
12
|
+
export type BackendKind = (typeof BACKEND_KINDS)[number];
|
|
13
|
+
export declare const backendKindSchema: z.ZodEnum<["oma", "claude_code", "pi", "omp"]>;
|
|
14
|
+
//# sourceMappingURL=kinds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../src/kinds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;kDAQkD;AAClD,eAAO,MAAM,aAAa,8CAA+C,CAAC;AAC1E,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD,eAAO,MAAM,iBAAiB,gDAAwB,CAAC"}
|
package/dist/kinds.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** The full set of execution backends the Product Backend can dispatch to.
|
|
3
|
+
* Each kind has exactly one adapter package implementing `AgentBackend<K>`:
|
|
4
|
+
* - oma: 自家 child (apps/oh-my-agent --mode rpc)
|
|
5
|
+
* - claude_code: Claude Code CLI (--output-format stream-json)
|
|
6
|
+
* - pi: pi CLI (@earendil-works/pi-oma, -p --mode json)
|
|
7
|
+
* - omp: omp CLI (@oh-my-pi/pi-oma, -p --mode json)
|
|
8
|
+
*
|
|
9
|
+
* The wire contract in transport.ts accepts this union; a child enforces
|
|
10
|
+
* its own kind at runtime (see oma rpc-mode). */
|
|
11
|
+
export const BACKEND_KINDS = ["oma", "claude_code", "pi", "omp"];
|
|
12
|
+
export const backendKindSchema = z.enum(BACKEND_KINDS);
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Stable reference to a model within a specific Agent Backend kind. `K`
|
|
2
|
+
* constrains the ref to the Backend's own kind so a Backend of kind "fake"
|
|
3
|
+
* cannot receive a "claude-code" model ref. */
|
|
4
|
+
export interface BackendModelRef<K extends string = string> {
|
|
5
|
+
readonly backendKind: K;
|
|
6
|
+
readonly modelId: string;
|
|
7
|
+
/** Thinking-mode effort (Anthropic-format `reasoning` param): none/low/
|
|
8
|
+
* high/max. Undefined = provider default. */
|
|
9
|
+
readonly reasoningEffort?: "none" | "low" | "high" | "max";
|
|
10
|
+
}
|
|
11
|
+
/** Backend-exposed model metadata. Aggregated by Product Backend across backends. */
|
|
12
|
+
export interface BackendModel {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly displayName: string;
|
|
15
|
+
readonly reasoning: boolean;
|
|
16
|
+
readonly inputModalities: readonly string[];
|
|
17
|
+
readonly contextWindow: number;
|
|
18
|
+
readonly maxOutputTokens: number;
|
|
19
|
+
readonly available: boolean;
|
|
20
|
+
readonly cost: {
|
|
21
|
+
input: number;
|
|
22
|
+
output: number;
|
|
23
|
+
cacheRead: number;
|
|
24
|
+
cacheWrite: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** A backend's model listing. ModelRef must match the catalog's backendKind. */
|
|
28
|
+
export interface BackendModelCatalog {
|
|
29
|
+
readonly backendKind: string;
|
|
30
|
+
readonly models: readonly BackendModel[];
|
|
31
|
+
}
|
|
32
|
+
/** Uniform per-kind catalog facade consumed by execution preflight and the
|
|
33
|
+
* /api/models aggregation. The registry key carries the kind; the catalog's
|
|
34
|
+
* own list() result keeps its backendKind for the wire. */
|
|
35
|
+
export interface BackendCatalog {
|
|
36
|
+
list(): Promise<{
|
|
37
|
+
readonly models: readonly BackendModel[];
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;gDAEgD;AAChD,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACxD,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;kDAC8C;IAC9C,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;CAC5D;AAED,qFAAqF;AACrF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CACzF;AAED,gFAAgF;AAChF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC;CAC1C;AAED;;4DAE4D;AAC5D,MAAM,WAAW,cAAc;IAC7B,IAAI,IAAI,OAAO,CAAC;QAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,CAAA;KAAE,CAAC,CAAC;CAC/D"}
|
package/dist/model.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/redact.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Secret collection + redaction for CLI child stderr: a crashed CLI echoing
|
|
2
|
+
* its environment must never write API keys into persistent run records. */
|
|
3
|
+
export declare function collectSecrets(env: Readonly<Record<string, string | undefined>>): string[];
|
|
4
|
+
export declare function redactText(text: string, secrets: readonly string[]): string;
|
|
5
|
+
//# sourceMappingURL=redact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":"AAAA;6EAC6E;AAa7E,wBAAgB,cAAc,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GAAG,MAAM,EAAE,CAS1F;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAO3E"}
|
package/dist/redact.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Secret collection + redaction for CLI child stderr: a crashed CLI echoing
|
|
2
|
+
* its environment must never write API keys into persistent run records. */
|
|
3
|
+
const REDACTED = "[REDACTED]";
|
|
4
|
+
const KNOWN_KEYS = [
|
|
5
|
+
"ANTHROPIC_API_KEY",
|
|
6
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
7
|
+
"OMA_PRODUCT_TOOL_TOKEN",
|
|
8
|
+
"PRODUCT_TOOLS_SERVICE_TOKEN",
|
|
9
|
+
"PRODUCT_TOOLS_RUN_TOKEN",
|
|
10
|
+
"BACKEND_AUTH_TOKEN",
|
|
11
|
+
];
|
|
12
|
+
export function collectSecrets(env) {
|
|
13
|
+
const secrets = new Set();
|
|
14
|
+
for (const [key, value] of Object.entries(env)) {
|
|
15
|
+
if (!value || value.length < 8)
|
|
16
|
+
continue;
|
|
17
|
+
if (KNOWN_KEYS.includes(key) || /TOKEN|KEY|SECRET|PASSWORD|AUTH/i.test(key)) {
|
|
18
|
+
secrets.add(value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return [...secrets];
|
|
22
|
+
}
|
|
23
|
+
export function redactText(text, secrets) {
|
|
24
|
+
let out = text;
|
|
25
|
+
for (const secret of secrets) {
|
|
26
|
+
if (!secret)
|
|
27
|
+
continue;
|
|
28
|
+
out = out.split(secret).join(REDACTED);
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
}
|
package/dist/run.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Message } from "@chengchenccc/message";
|
|
2
|
+
import type { BackendEvent, Usage } from "./event.js";
|
|
3
|
+
import type { AgentRunSnapshot, WorkspaceBinding } from "./history.js";
|
|
4
|
+
/** The actual execution input crossing the Backend boundary: the durable
|
|
5
|
+
* Product input-queue identity plus the canonical Message it carries.
|
|
6
|
+
*
|
|
7
|
+
* - `inputId` is generated by the Product Backend's durable input queue and
|
|
8
|
+
* is the stable idempotency source for every mutation that submits this
|
|
9
|
+
* input. The Adapter/child MUST NOT regenerate it.
|
|
10
|
+
* - `message` is the canonical Message (user/steer/follow-up). It is the sole
|
|
11
|
+
* "actual prompt" - the Backend never infers a prompt from history and never
|
|
12
|
+
* fabricates placeholder text.
|
|
13
|
+
* - `productEntryId` is set when this input has already produced an Agent
|
|
14
|
+
* Context entry; the Runtime writes it onto the prompt/steer/follow-up entry
|
|
15
|
+
* it appends, so the same canonical Message is never persisted twice. */
|
|
16
|
+
export interface BackendInputMessage {
|
|
17
|
+
readonly inputId: string;
|
|
18
|
+
readonly message: Message;
|
|
19
|
+
readonly productEntryId?: string;
|
|
20
|
+
}
|
|
21
|
+
/** The complete durable facts of one Agent Run crossing the Backend boundary.
|
|
22
|
+
* History is NOT part of the contract (ADR 0003 decision 6): the first-turn
|
|
23
|
+
* bridge is flat text inside `input.message` (rendered by the Backend when
|
|
24
|
+
* the branch has no CLI session reference yet); from the second turn on the
|
|
25
|
+
* CLI session is the runtime truth. `workspace` is a Run execution fact (the
|
|
26
|
+
* caller pins the cloned repo for Loop Runs, the agent-record workspace
|
|
27
|
+
* otherwise), never re-derived by the Backend. Parameterized by `K` so the
|
|
28
|
+
* snapshot's model ref is locked to the Backend's kind. */
|
|
29
|
+
export interface BackendRunInput<K extends string = string> {
|
|
30
|
+
readonly input: BackendInputMessage;
|
|
31
|
+
readonly run: AgentRunSnapshot<K>;
|
|
32
|
+
readonly workspace: WorkspaceBinding;
|
|
33
|
+
/** Per-run product-tools bearer. Backends deliver it to their child
|
|
34
|
+
* (spawn env). Absent = no product tools for this run. */
|
|
35
|
+
readonly productToolsToken?: string;
|
|
36
|
+
/** True when the conversation already has a title — the child skips
|
|
37
|
+
* auto-title generation (checked again server-side on commit). */
|
|
38
|
+
readonly convTitled?: boolean;
|
|
39
|
+
/** Oma-only execution mode: run the workflow SCRIPT directly (vm sandbox,
|
|
40
|
+
* agent() subagents) instead of an interactive loop. The script's return
|
|
41
|
+
* value becomes `outcome.workflow.value`. Other backends ignore it. */
|
|
42
|
+
readonly workflow?: {
|
|
43
|
+
readonly script: string;
|
|
44
|
+
readonly args?: unknown;
|
|
45
|
+
};
|
|
46
|
+
/** Product-run identity (conversation/agent/branch). Optional: the RPC
|
|
47
|
+
* product path always sends it (wire schema requires it); standalone CLI
|
|
48
|
+
* runs (TUI/print) omit it and carry no product identity. */
|
|
49
|
+
readonly metadata?: {
|
|
50
|
+
readonly conversationId: string;
|
|
51
|
+
readonly agentId: string;
|
|
52
|
+
readonly branchId: string;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** A pending approval, question or permission request awaiting a product
|
|
56
|
+
* control-plane response. Product-side record; not part of the Run protocol. */
|
|
57
|
+
export interface PendingAction {
|
|
58
|
+
readonly actionId: string;
|
|
59
|
+
readonly kind: string;
|
|
60
|
+
readonly payload: Readonly<Record<string, unknown>>;
|
|
61
|
+
}
|
|
62
|
+
/** Structured response to a PendingAction. Carries `actionId` for idempotency;
|
|
63
|
+
* each actionId is consumed at most once. */
|
|
64
|
+
export interface PendingActionResponse {
|
|
65
|
+
readonly actionId: string;
|
|
66
|
+
readonly response: unknown;
|
|
67
|
+
}
|
|
68
|
+
/** Terminal outcome of a Run. `completed`, `failed`, `aborted` and `timeout`
|
|
69
|
+
* are the four terminal states. This is the ONLY terminal authority - event
|
|
70
|
+
* streams must never be interpreted as terminal.
|
|
71
|
+
*
|
|
72
|
+
* A completed Run carries the full canonical message sequence it produced
|
|
73
|
+
* (ADR 0017): assistant(tool_use) / tool(tool_result) / assistant(text) as
|
|
74
|
+
* separate messages, in order, ready to be persisted and replayed. The
|
|
75
|
+
* final answer is the last assistant message with text. */
|
|
76
|
+
export type BackendRunOutcome = {
|
|
77
|
+
readonly status: "completed";
|
|
78
|
+
readonly messages?: readonly Message[];
|
|
79
|
+
readonly usage?: Usage;
|
|
80
|
+
readonly title?: string;
|
|
81
|
+
/** CLI-side session reference (ADR 0002): claude session_id or a
|
|
82
|
+
* pi/omp session file path. Product Backend persists it on the
|
|
83
|
+
* branch (agent_context_branch.cli_session_ref) as the runtime
|
|
84
|
+
* truth for context continuation. */
|
|
85
|
+
readonly cliSessionRef?: string;
|
|
86
|
+
/** Oma workflow-mode result: the script's return value + aggregate
|
|
87
|
+
* subagent usage. Present when the run executed via input.workflow. */
|
|
88
|
+
readonly workflow?: {
|
|
89
|
+
readonly ok: boolean;
|
|
90
|
+
readonly value: unknown;
|
|
91
|
+
readonly usage?: Usage;
|
|
92
|
+
};
|
|
93
|
+
} | {
|
|
94
|
+
readonly status: "failed" | "aborted" | "timeout";
|
|
95
|
+
readonly error?: string;
|
|
96
|
+
readonly usage?: Usage;
|
|
97
|
+
readonly cliSessionRef?: string;
|
|
98
|
+
/** Messages persisted before the terminal failure (max steps,
|
|
99
|
+
* mid-task error) — lets a follow-up turn resume the context. */
|
|
100
|
+
readonly messages?: readonly Message[];
|
|
101
|
+
};
|
|
102
|
+
/** A single run segment: an event stream plus a terminal outcome promise.
|
|
103
|
+
* `stop()` requests cancellation; the outcome still resolves. Parameterized by
|
|
104
|
+
* `K` so events are namespaced to the Backend's kind. */
|
|
105
|
+
export interface BackendRunSegment<K extends string = string> {
|
|
106
|
+
readonly events: AsyncIterable<BackendEvent<K>>;
|
|
107
|
+
readonly outcome: Promise<BackendRunOutcome>;
|
|
108
|
+
stop(): Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEvE;;;;;;;;;;;4EAW4E;AAC5E,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CA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C,EAAE,SAAS,OAAO,EAAE,CAAC;IACvC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;0CAGsC;IACtC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC;4EACwE;IACxE,QAAQ,CAAC,QAAQ,CAAC,EAAE;QAClB,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;QACrB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;QACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;KACxB,CAAC;CACH,GACD;IACE,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IAClD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC;sEACkE;IAClE,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;CACxC,CAAC;AAEN;;0DAE0D;AAC1D,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAC1D,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC7C,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB"}
|
package/dist/run.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chengchenccc/agent-contract",
|
|
3
|
+
"version": "0.1.1-rc.1",
|
|
4
|
+
"description": "Implementation-independent Agent Backend contracts",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"default": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.json",
|
|
18
|
+
"lint": "biome check . && eslint .",
|
|
19
|
+
"test": "bun test",
|
|
20
|
+
"typecheck": "tsc -p tsconfig.test.json --noEmit"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@chengchenccc/message": "^0.1.1-rc.1",
|
|
24
|
+
"zod": "^3.23.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/Chengchcc/my-agent-team.git",
|
|
30
|
+
"directory": "packages/agent-contract"
|
|
31
|
+
}
|
|
32
|
+
}
|