@arnilo/prism 0.1.2 → 0.1.4

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/agent-approval.d.ts +49 -0
  3. package/dist/agent-approval.js +178 -0
  4. package/dist/agent-run-lifecycle.d.ts +7 -1
  5. package/dist/agent-run-lifecycle.js +213 -3
  6. package/dist/agent-run-state.d.ts +11 -0
  7. package/dist/agent-run-state.js +23 -0
  8. package/dist/agent-session.d.ts +98 -0
  9. package/dist/agent-session.js +1806 -0
  10. package/dist/agent-tool-dispatch.d.ts +13 -0
  11. package/dist/agent-tool-dispatch.js +92 -0
  12. package/dist/agents.d.ts +16 -9
  13. package/dist/agents.js +14 -2254
  14. package/dist/contracts-core.d.ts +1402 -0
  15. package/dist/contracts-core.js +119 -0
  16. package/dist/contracts-protocol.d.ts +596 -0
  17. package/dist/contracts-protocol.js +2 -0
  18. package/dist/contracts-run-state.d.ts +285 -0
  19. package/dist/contracts-run-state.js +77 -0
  20. package/dist/contracts.d.ts +7 -2261
  21. package/dist/contracts.js +7 -192
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.js +1 -1
  24. package/docs/0.1.0-readiness.md +3 -1
  25. package/docs/agent-identity.md +1 -1
  26. package/docs/agent-session-runtime.md +3 -1
  27. package/docs/browser-automation.md +13 -9
  28. package/docs/coding-agent-tools.md +13 -0
  29. package/docs/context-and-skills.md +2 -2
  30. package/docs/index.md +3 -14
  31. package/docs/migration.md +11 -5
  32. package/docs/performance.md +14 -4
  33. package/docs/persistence-credentials-multimodality-primitives.md +1 -1
  34. package/docs/provider-primitives.md +1 -1
  35. package/docs/public-contracts.md +2 -0
  36. package/docs/release-and-install.md +65 -0
  37. package/docs/session-stores.md +2 -2
  38. package/docs/thinking-and-reasoning.md +1 -1
  39. package/docs/tool-execution-primitives.md +2 -2
  40. package/docs/use-case-model-selection.md +1 -1
  41. package/docs/workflow-orchestration-primitives.md +1 -1
  42. package/package.json +4 -3
@@ -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
- import type { Agent, AgentConfig, AgentEvent, AgentRunRef, AgentRunResult, AgentRunResume, AgentRunResumeOptions, AgentRunResumeStreamOptions, AgentSession, AgentSessionConfig } from "./contracts.js";
2
- export declare function createAgent(config: AgentConfig): Agent;
3
- export declare function createAgentSession(config: AgentSessionConfig & {
4
- readonly agent: Agent;
5
- }): AgentSession;
6
- /** Resume a persisted built-in run. A claimed/dispatched tool is never replayed automatically. */
7
- export declare function resumeAgentRun(agent: Agent, ref: AgentRunRef, resume: AgentRunResume, options: AgentRunResumeOptions): Promise<AgentRunResult>;
8
- /** Subscribe before resuming one durable run. Early consumer return aborts that resumed execution. */
9
- export declare function resumeAgentRunStream(agent: Agent, ref: AgentRunRef, resume: AgentRunResume, options: AgentRunResumeStreamOptions): AsyncGenerator<AgentEvent>;
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";