@arnilo/prism 0.1.3 → 0.1.5
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/CHANGELOG.md +10 -0
- package/dist/agent-approval.d.ts +49 -0
- package/dist/agent-approval.js +178 -0
- package/dist/agent-run-lifecycle.d.ts +5 -1
- package/dist/agent-run-lifecycle.js +211 -3
- package/dist/agent-session.d.ts +98 -0
- package/dist/agent-session.js +1811 -0
- package/dist/agent-tool-dispatch.d.ts +13 -0
- package/dist/agent-tool-dispatch.js +92 -0
- package/dist/agents.d.ts +16 -9
- package/dist/agents.js +14 -2267
- package/dist/cli-init.d.ts +0 -2
- package/dist/cli-init.js +0 -2
- package/dist/cli-runner.js +1 -1
- package/dist/contracts-core.d.ts +1396 -0
- package/dist/contracts-core.js +119 -0
- package/dist/contracts-protocol.d.ts +594 -0
- package/dist/contracts-protocol.js +2 -0
- package/dist/contracts-run-state.d.ts +285 -0
- package/dist/contracts-run-state.js +77 -0
- package/dist/contracts.d.ts +7 -2269
- package/dist/contracts.js +7 -192
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/rpc.js +2 -1
- package/docs/agent-loops.md +1 -1
- package/docs/agent-session-runtime.md +4 -2
- package/docs/browser-automation.md +13 -9
- package/docs/coding-agent-tools.md +1 -2
- package/docs/compaction-observational-memory.md +5 -6
- package/docs/index.md +4 -4
- package/docs/migration.md +114 -1
- package/docs/performance.md +10 -0
- package/docs/provider-conformance.md +2 -2
- package/docs/provider-layer.md +1 -1
- package/docs/provider-packages.md +1 -1
- package/docs/provider-primitives.md +1 -1
- package/docs/public-contracts.md +4 -2
- package/docs/release-and-install.md +64 -0
- package/docs/tool-execution-primitives.md +3 -3
- package/docs/tools.md +2 -2
- package/docs/use-case-model-selection.md +12 -11
- package/package.json +2 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StoredAgentRunState } from "./agent-run-state.js";
|
|
2
|
+
import { Agent, AgentConfig, JsonObject, PendingDecision, ProviderRequestPolicy, ToolDefinition, ToolExecutionContext, ToolRegistry } from "./contracts.js";
|
|
3
|
+
export declare function toolElicitationRequest(tool: ToolDefinition | undefined, args: JsonObject, context: ToolExecutionContext): {
|
|
4
|
+
schema: JsonObject;
|
|
5
|
+
reason?: string;
|
|
6
|
+
} | undefined;
|
|
7
|
+
/** Elicitation payload check: bounded JSON object, schema-required keys, host validator when configured. */
|
|
8
|
+
export declare function validateElicitationPayload(agent: Agent, state: StoredAgentRunState, target: PendingDecision, payload: JsonObject, signal?: AbortSignal): Promise<void>;
|
|
9
|
+
export declare function activeTools(tools: AgentConfig["tools"]): {
|
|
10
|
+
registry: ToolRegistry;
|
|
11
|
+
tools: readonly ToolDefinition[];
|
|
12
|
+
};
|
|
13
|
+
export declare function policyList(policies: ProviderRequestPolicy | readonly ProviderRequestPolicy[] | undefined): readonly ProviderRequestPolicy[];
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { AgentDecisionError, HARD_MAX_ELICITATION_BYTES, MAX_DECISION_REASON_BYTES, MAX_ELICITATION_BYTES, } from "./contracts.js";
|
|
2
|
+
import { createToolRegistry } from "./tools.js";
|
|
3
|
+
export function toolElicitationRequest(tool, args, context) {
|
|
4
|
+
if (!tool?.elicitation)
|
|
5
|
+
return undefined;
|
|
6
|
+
let request;
|
|
7
|
+
try {
|
|
8
|
+
request = tool.elicitation(args, context);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
if (!request)
|
|
14
|
+
return undefined;
|
|
15
|
+
const schemaText = JSON.stringify(request.schema);
|
|
16
|
+
if (schemaText === undefined || Buffer.byteLength(schemaText, "utf8") > HARD_MAX_ELICITATION_BYTES)
|
|
17
|
+
return undefined;
|
|
18
|
+
const reason = request.reason;
|
|
19
|
+
if (reason !== undefined && Buffer.byteLength(reason, "utf8") > MAX_DECISION_REASON_BYTES)
|
|
20
|
+
return { schema: request.schema };
|
|
21
|
+
return { schema: request.schema, ...(reason !== undefined ? { reason } : {}) };
|
|
22
|
+
}
|
|
23
|
+
/** Elicitation payload check: bounded JSON object, schema-required keys, host validator when configured. */
|
|
24
|
+
export async function validateElicitationPayload(agent, state, target, payload, signal) {
|
|
25
|
+
const invalid = (message) => new AgentDecisionError("ERR_PRISM_DECISION_INVALID", message);
|
|
26
|
+
const text = JSON.stringify(payload);
|
|
27
|
+
if (text === undefined || Buffer.byteLength(text, "utf8") > MAX_ELICITATION_BYTES) {
|
|
28
|
+
throw new AgentDecisionError("ERR_PRISM_DECISION_LIMIT", `Elicitation payload exceeds ${MAX_ELICITATION_BYTES} bytes`);
|
|
29
|
+
}
|
|
30
|
+
const schema = target.elicitationSchema;
|
|
31
|
+
if (schema) {
|
|
32
|
+
const required = schema.required;
|
|
33
|
+
if (Array.isArray(required)) {
|
|
34
|
+
for (const key of required) {
|
|
35
|
+
if (typeof key === "string" && !Object.hasOwn(payload, key))
|
|
36
|
+
throw invalid(`Elicitation payload missing required key ${key}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (agent.config.validator) {
|
|
40
|
+
const tool = {
|
|
41
|
+
name: target.scope.toolName ?? "elicitation",
|
|
42
|
+
parameters: schema,
|
|
43
|
+
execute: () => ({ toolCallId: "", name: "elicitation" }),
|
|
44
|
+
};
|
|
45
|
+
const context = { sessionId: state.sessionId, runId: state.runId, toolCallId: target.toolCallId ?? "elicitation", signal };
|
|
46
|
+
const validation = await agent.config.validator(tool, payload, context);
|
|
47
|
+
if (validation)
|
|
48
|
+
throw invalid("Elicitation payload failed schema validation");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Tool-declared answer-shape validation, re-derived from the current registry (never persisted).
|
|
52
|
+
const call = state.pendingCalls?.find((entry) => entry.call.id === target.toolCallId)?.call;
|
|
53
|
+
const tool = call ? activeTools(agent.config.tools).registry.get(call.name) : undefined;
|
|
54
|
+
const validate = tool?.elicitation && call
|
|
55
|
+
? safeToolElicitationValidate(tool, call.arguments, {
|
|
56
|
+
sessionId: state.sessionId,
|
|
57
|
+
runId: state.runId,
|
|
58
|
+
toolCallId: target.toolCallId ?? "elicitation",
|
|
59
|
+
signal,
|
|
60
|
+
})
|
|
61
|
+
: undefined;
|
|
62
|
+
if (validate) {
|
|
63
|
+
try {
|
|
64
|
+
validate(payload);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
throw invalid(error instanceof Error ? error.message : "Elicitation payload rejected by tool validation");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function safeToolElicitationValidate(tool, args, context) {
|
|
72
|
+
try {
|
|
73
|
+
return tool.elicitation(args, context)?.validate;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function activeTools(tools) {
|
|
80
|
+
if (!tools)
|
|
81
|
+
return { registry: createToolRegistry(), tools: [] };
|
|
82
|
+
if ("list" in tools)
|
|
83
|
+
return { registry: tools, tools: tools.list() };
|
|
84
|
+
const registry = createToolRegistry(tools);
|
|
85
|
+
return { registry, tools };
|
|
86
|
+
}
|
|
87
|
+
export function policyList(policies) {
|
|
88
|
+
if (!policies)
|
|
89
|
+
return [];
|
|
90
|
+
return "apply" in policies ? [policies] : policies;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=agent-tool-dispatch.js.map
|
package/dist/agents.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Barrel for the agent runtime split at 0.1.4 (compat-preserving internal reorg).
|
|
3
|
+
* The four public exports (createAgent, createAgentSession, resumeAgentRun,
|
|
4
|
+
* resumeAgentRunStream) stay reachable through this barrel; RuntimeAgentSession,
|
|
5
|
+
* EventSubscriber, and the shared helpers live in agent-session.ts; the
|
|
6
|
+
* approval/pending-decision helpers in agent-approval.ts; the tool-dispatch
|
|
7
|
+
* helpers in agent-tool-dispatch.ts; the resume free functions in
|
|
8
|
+
* agent-run-lifecycle.ts; the fingerprint helpers in agent-run-state.ts.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately NOT `export *`: star re-exports would surface the split modules'
|
|
11
|
+
* internal helpers (RuntimeAgentSession, pendingDecisionsOf, …) through
|
|
12
|
+
* agents.d.ts and change the declared surface — the 0.1.4 promise is an
|
|
13
|
+
* identical surface.
|
|
14
|
+
*/
|
|
15
|
+
export { createAgent, createAgentSession } from "./agent-session.js";
|
|
16
|
+
export { resumeAgentRun, resumeAgentRunStream } from "./agent-run-lifecycle.js";
|