agent-framework-js 0.1.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.
Files changed (156) hide show
  1. package/AGENT_USAGE.md +207 -0
  2. package/LICENSE +21 -0
  3. package/README.md +99 -0
  4. package/dist/agents/index.cjs +35 -0
  5. package/dist/agents/index.cjs.map +1 -0
  6. package/dist/agents/index.d.cts +8 -0
  7. package/dist/agents/index.d.ts +8 -0
  8. package/dist/agents/index.js +10 -0
  9. package/dist/agents/index.js.map +1 -0
  10. package/dist/chunk-5M6ER4ZX.cjs +4 -0
  11. package/dist/chunk-5M6ER4ZX.cjs.map +1 -0
  12. package/dist/chunk-5PDJOBTD.js +38 -0
  13. package/dist/chunk-5PDJOBTD.js.map +1 -0
  14. package/dist/chunk-7ZXUIHLH.js +18 -0
  15. package/dist/chunk-7ZXUIHLH.js.map +1 -0
  16. package/dist/chunk-ACBIHS5H.js +30 -0
  17. package/dist/chunk-ACBIHS5H.js.map +1 -0
  18. package/dist/chunk-DEABART4.js +54 -0
  19. package/dist/chunk-DEABART4.js.map +1 -0
  20. package/dist/chunk-FOTCUNP5.cjs +34 -0
  21. package/dist/chunk-FOTCUNP5.cjs.map +1 -0
  22. package/dist/chunk-FSDMBWQV.cjs +20 -0
  23. package/dist/chunk-FSDMBWQV.cjs.map +1 -0
  24. package/dist/chunk-GYDY3KX5.cjs +72 -0
  25. package/dist/chunk-GYDY3KX5.cjs.map +1 -0
  26. package/dist/chunk-HGEPXJDG.js +129 -0
  27. package/dist/chunk-HGEPXJDG.js.map +1 -0
  28. package/dist/chunk-IJASUMIQ.cjs +57 -0
  29. package/dist/chunk-IJASUMIQ.cjs.map +1 -0
  30. package/dist/chunk-IU3LS5FC.cjs +10 -0
  31. package/dist/chunk-IU3LS5FC.cjs.map +1 -0
  32. package/dist/chunk-IUKD54F7.js +8 -0
  33. package/dist/chunk-IUKD54F7.js.map +1 -0
  34. package/dist/chunk-IXV4UIF5.js +79 -0
  35. package/dist/chunk-IXV4UIF5.js.map +1 -0
  36. package/dist/chunk-KEI3EALJ.cjs +10 -0
  37. package/dist/chunk-KEI3EALJ.cjs.map +1 -0
  38. package/dist/chunk-LMN75W3W.cjs +87 -0
  39. package/dist/chunk-LMN75W3W.cjs.map +1 -0
  40. package/dist/chunk-MCLVWCOB.js +3 -0
  41. package/dist/chunk-MCLVWCOB.js.map +1 -0
  42. package/dist/chunk-MQ2XTH3S.cjs +87 -0
  43. package/dist/chunk-MQ2XTH3S.cjs.map +1 -0
  44. package/dist/chunk-QJ5XHA6S.cjs +95 -0
  45. package/dist/chunk-QJ5XHA6S.cjs.map +1 -0
  46. package/dist/chunk-RD5YUB2E.js +190 -0
  47. package/dist/chunk-RD5YUB2E.js.map +1 -0
  48. package/dist/chunk-RZ43WNHR.js +8 -0
  49. package/dist/chunk-RZ43WNHR.js.map +1 -0
  50. package/dist/chunk-RZP2ZUUX.cjs +252 -0
  51. package/dist/chunk-RZP2ZUUX.cjs.map +1 -0
  52. package/dist/chunk-T2GHJ5R4.js +241 -0
  53. package/dist/chunk-T2GHJ5R4.js.map +1 -0
  54. package/dist/chunk-TAMJ5HSR.cjs +137 -0
  55. package/dist/chunk-TAMJ5HSR.cjs.map +1 -0
  56. package/dist/chunk-TLACSVEZ.cjs +201 -0
  57. package/dist/chunk-TLACSVEZ.cjs.map +1 -0
  58. package/dist/chunk-UVWQWOLO.js +196 -0
  59. package/dist/chunk-UVWQWOLO.js.map +1 -0
  60. package/dist/chunk-V472N2PK.js +91 -0
  61. package/dist/chunk-V472N2PK.js.map +1 -0
  62. package/dist/chunk-V6O6SYAN.cjs +43 -0
  63. package/dist/chunk-V6O6SYAN.cjs.map +1 -0
  64. package/dist/chunk-VLSVL5N2.js +48 -0
  65. package/dist/chunk-VLSVL5N2.js.map +1 -0
  66. package/dist/chunk-WSMYH2IN.cjs +86 -0
  67. package/dist/chunk-WSMYH2IN.cjs.map +1 -0
  68. package/dist/chunk-XPXTXOYQ.js +81 -0
  69. package/dist/chunk-XPXTXOYQ.js.map +1 -0
  70. package/dist/chunk-YBFLWRO5.cjs +194 -0
  71. package/dist/chunk-YBFLWRO5.cjs.map +1 -0
  72. package/dist/chunk-YCBDEEAV.js +82 -0
  73. package/dist/chunk-YCBDEEAV.js.map +1 -0
  74. package/dist/chunk-YH5746OF.js +69 -0
  75. package/dist/chunk-YH5746OF.js.map +1 -0
  76. package/dist/chunk-YKZJRE32.cjs +50 -0
  77. package/dist/chunk-YKZJRE32.cjs.map +1 -0
  78. package/dist/declarative/index.cjs +19 -0
  79. package/dist/declarative/index.cjs.map +1 -0
  80. package/dist/declarative/index.d.cts +60 -0
  81. package/dist/declarative/index.d.ts +60 -0
  82. package/dist/declarative/index.js +10 -0
  83. package/dist/declarative/index.js.map +1 -0
  84. package/dist/errors-CjVz4W_5.d.cts +68 -0
  85. package/dist/errors-CjVz4W_5.d.ts +68 -0
  86. package/dist/index-C2vzfbBz.d.cts +57 -0
  87. package/dist/index-C2vzfbBz.d.ts +57 -0
  88. package/dist/index-D7-znzrc.d.ts +153 -0
  89. package/dist/index-DdYZeNIu.d.cts +153 -0
  90. package/dist/index.cjs +236 -0
  91. package/dist/index.cjs.map +1 -0
  92. package/dist/index.d.cts +51 -0
  93. package/dist/index.d.ts +51 -0
  94. package/dist/index.js +19 -0
  95. package/dist/index.js.map +1 -0
  96. package/dist/mcp/index.cjs +19 -0
  97. package/dist/mcp/index.cjs.map +1 -0
  98. package/dist/mcp/index.d.cts +72 -0
  99. package/dist/mcp/index.d.ts +72 -0
  100. package/dist/mcp/index.js +6 -0
  101. package/dist/mcp/index.js.map +1 -0
  102. package/dist/middleware/index.cjs +17 -0
  103. package/dist/middleware/index.cjs.map +1 -0
  104. package/dist/middleware/index.d.cts +29 -0
  105. package/dist/middleware/index.d.ts +29 -0
  106. package/dist/middleware/index.js +4 -0
  107. package/dist/middleware/index.js.map +1 -0
  108. package/dist/observability/index.cjs +29 -0
  109. package/dist/observability/index.cjs.map +1 -0
  110. package/dist/observability/index.d.cts +1 -0
  111. package/dist/observability/index.d.ts +1 -0
  112. package/dist/observability/index.js +4 -0
  113. package/dist/observability/index.js.map +1 -0
  114. package/dist/persistence/index.cjs +24 -0
  115. package/dist/persistence/index.cjs.map +1 -0
  116. package/dist/persistence/index.d.cts +51 -0
  117. package/dist/persistence/index.d.ts +51 -0
  118. package/dist/persistence/index.js +7 -0
  119. package/dist/persistence/index.js.map +1 -0
  120. package/dist/provider-CMAymr1b.d.cts +82 -0
  121. package/dist/provider-osAtfZ7x.d.ts +82 -0
  122. package/dist/providers/index.cjs +26 -0
  123. package/dist/providers/index.cjs.map +1 -0
  124. package/dist/providers/index.d.cts +107 -0
  125. package/dist/providers/index.d.ts +107 -0
  126. package/dist/providers/index.js +5 -0
  127. package/dist/providers/index.js.map +1 -0
  128. package/dist/registry-CpO0yH5v.d.ts +57 -0
  129. package/dist/registry-D4fThGiN.d.cts +57 -0
  130. package/dist/skill-DfNChtJN.d.cts +45 -0
  131. package/dist/skill-DfNChtJN.d.ts +45 -0
  132. package/dist/skills/index.cjs +20 -0
  133. package/dist/skills/index.cjs.map +1 -0
  134. package/dist/skills/index.d.cts +30 -0
  135. package/dist/skills/index.d.ts +30 -0
  136. package/dist/skills/index.js +3 -0
  137. package/dist/skills/index.js.map +1 -0
  138. package/dist/thread-CWVzTyti.d.ts +51 -0
  139. package/dist/thread-Dfo9LLf7.d.cts +51 -0
  140. package/dist/tool-BZg_znMZ.d.cts +50 -0
  141. package/dist/tool-CSCC87OD.d.ts +50 -0
  142. package/dist/tools/index.cjs +27 -0
  143. package/dist/tools/index.cjs.map +1 -0
  144. package/dist/tools/index.d.cts +21 -0
  145. package/dist/tools/index.d.ts +21 -0
  146. package/dist/tools/index.js +6 -0
  147. package/dist/tools/index.js.map +1 -0
  148. package/dist/types-Cn1g9Tg4.d.cts +63 -0
  149. package/dist/types-Cn1g9Tg4.d.ts +63 -0
  150. package/dist/workflows/index.cjs +50 -0
  151. package/dist/workflows/index.cjs.map +1 -0
  152. package/dist/workflows/index.d.cts +182 -0
  153. package/dist/workflows/index.d.ts +182 -0
  154. package/dist/workflows/index.js +5 -0
  155. package/dist/workflows/index.js.map +1 -0
  156. package/package.json +145 -0
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Centralized secret redaction applied at every output boundary (logs, traces,
3
+ * serialized errors). Security is secure-by-default: no credential value may
4
+ * appear in any emitted output. (FR-026, FR-026a, Constitution II)
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ /** Placeholder substituted for redacted values. */
9
+ declare const REDACTED = "[REDACTED]";
10
+ /**
11
+ * Return a deep copy of `value` with secrets scrubbed. Safe for arbitrary
12
+ * structures; handles cycles. Never mutates the input.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * redact({ authorization: "Bearer abc" }); // => { authorization: "[REDACTED]" }
17
+ * ```
18
+ */
19
+ declare function redact<T>(value: T): T;
20
+
21
+ /**
22
+ * Observability via OpenTelemetry. Consumers supply their own tracer/exporters;
23
+ * the framework emits spans for agent/tool/provider/workflow operations and routes
24
+ * all attributes and errors through redaction so no secret ever leaks. (FR-025,
25
+ * FR-026, FR-026a)
26
+ *
27
+ * The `@opentelemetry/api` package is an optional peer dependency.
28
+ *
29
+ * @packageDocumentation
30
+ */
31
+
32
+ type Tracer = any;
33
+ /** Configuration for {@link configureObservability}. */
34
+ interface ObservabilityConfig {
35
+ /** A consumer-supplied OpenTelemetry tracer. */
36
+ tracer?: Tracer;
37
+ /** Whether tracing is active. Default false. */
38
+ enabled?: boolean;
39
+ }
40
+ /** Enable/disable tracing and set the tracer. */
41
+ declare function configureObservability(config: ObservabilityConfig): void;
42
+
43
+ /**
44
+ * Run `fn` inside a span named `name`. Attributes are redacted before being set.
45
+ * If tracing is disabled or no tracer is configured, `fn` runs without a span.
46
+ *
47
+ * @param name - Span name, e.g. `agent.run`, `tool.invoke`.
48
+ * @param attributes - Span attributes (redacted automatically).
49
+ * @param fn - The operation to trace.
50
+ */
51
+ declare function withSpan<T>(name: string, attributes: Record<string, unknown>, fn: () => Promise<T>): Promise<T>;
52
+ /** Whether tracing is currently active. */
53
+ declare function isObservabilityEnabled(): boolean;
54
+ /** Reset observability state — intended for tests. */
55
+ declare function resetObservability(): void;
56
+
57
+ export { type ObservabilityConfig as O, REDACTED as R, resetObservability as a, configureObservability as c, isObservabilityEnabled as i, redact as r, withSpan as w };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Centralized secret redaction applied at every output boundary (logs, traces,
3
+ * serialized errors). Security is secure-by-default: no credential value may
4
+ * appear in any emitted output. (FR-026, FR-026a, Constitution II)
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ /** Placeholder substituted for redacted values. */
9
+ declare const REDACTED = "[REDACTED]";
10
+ /**
11
+ * Return a deep copy of `value` with secrets scrubbed. Safe for arbitrary
12
+ * structures; handles cycles. Never mutates the input.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * redact({ authorization: "Bearer abc" }); // => { authorization: "[REDACTED]" }
17
+ * ```
18
+ */
19
+ declare function redact<T>(value: T): T;
20
+
21
+ /**
22
+ * Observability via OpenTelemetry. Consumers supply their own tracer/exporters;
23
+ * the framework emits spans for agent/tool/provider/workflow operations and routes
24
+ * all attributes and errors through redaction so no secret ever leaks. (FR-025,
25
+ * FR-026, FR-026a)
26
+ *
27
+ * The `@opentelemetry/api` package is an optional peer dependency.
28
+ *
29
+ * @packageDocumentation
30
+ */
31
+
32
+ type Tracer = any;
33
+ /** Configuration for {@link configureObservability}. */
34
+ interface ObservabilityConfig {
35
+ /** A consumer-supplied OpenTelemetry tracer. */
36
+ tracer?: Tracer;
37
+ /** Whether tracing is active. Default false. */
38
+ enabled?: boolean;
39
+ }
40
+ /** Enable/disable tracing and set the tracer. */
41
+ declare function configureObservability(config: ObservabilityConfig): void;
42
+
43
+ /**
44
+ * Run `fn` inside a span named `name`. Attributes are redacted before being set.
45
+ * If tracing is disabled or no tracer is configured, `fn` runs without a span.
46
+ *
47
+ * @param name - Span name, e.g. `agent.run`, `tool.invoke`.
48
+ * @param attributes - Span attributes (redacted automatically).
49
+ * @param fn - The operation to trace.
50
+ */
51
+ declare function withSpan<T>(name: string, attributes: Record<string, unknown>, fn: () => Promise<T>): Promise<T>;
52
+ /** Whether tracing is currently active. */
53
+ declare function isObservabilityEnabled(): boolean;
54
+ /** Reset observability state — intended for tests. */
55
+ declare function resetObservability(): void;
56
+
57
+ export { type ObservabilityConfig as O, REDACTED as R, resetObservability as a, configureObservability as c, isObservabilityEnabled as i, redact as r, withSpan as w };
@@ -0,0 +1,153 @@
1
+ import { M as Message } from './types-Cn1g9Tg4.js';
2
+ import { P as ProviderError } from './errors-CjVz4W_5.js';
3
+ import { a as GenerateRequest, b as GenerateResponse, P as Provider } from './provider-osAtfZ7x.js';
4
+ import { T as Tool } from './tool-CSCC87OD.js';
5
+ import { S as Skill } from './skill-DfNChtJN.js';
6
+ import { T as Thread } from './thread-CWVzTyti.js';
7
+ import { T as ToolRegistry } from './registry-CpO0yH5v.js';
8
+
9
+ /**
10
+ * Middleware pipeline for intercepting and processing agent provider calls —
11
+ * request/response transformation, custom pipelines, and error handling. (FR-023)
12
+ *
13
+ * @packageDocumentation
14
+ */
15
+
16
+ /** Context passed through the middleware chain for one provider call. */
17
+ interface MiddlewareContext {
18
+ /** The agent's name. */
19
+ agentName: string;
20
+ /** The outgoing request (may be mutated by middleware). */
21
+ request: GenerateRequest;
22
+ }
23
+ /** Continue to the next middleware (or the provider call itself). */
24
+ type Next = () => Promise<GenerateResponse>;
25
+ /** A pipeline interceptor. */
26
+ interface Middleware {
27
+ name: string;
28
+ handle(ctx: MiddlewareContext, next: Next): Promise<GenerateResponse>;
29
+ }
30
+ /**
31
+ * Compose middleware into a single function wrapping `core`.
32
+ *
33
+ * @param middleware - Ordered interceptors (first runs outermost).
34
+ * @param core - The terminal operation (the actual provider call).
35
+ */
36
+ declare function composeMiddleware(middleware: Middleware[], core: (ctx: MiddlewareContext) => Promise<GenerateResponse>): (ctx: MiddlewareContext) => Promise<GenerateResponse>;
37
+
38
+ /**
39
+ * The agent run loop: drives provider calls, executes requested tool calls,
40
+ * feeds typed results (including errors, for self-correction) back to the model,
41
+ * and stops on a final answer, the iteration cap, or an abort. (FR-011a, FR-012b)
42
+ *
43
+ * @packageDocumentation
44
+ */
45
+
46
+ /** Outcome status of a run. */
47
+ type RunStatus = "completed" | "failed" | "incomplete" | "limit-exceeded";
48
+ /** A function that produces a model response (optionally through middleware). */
49
+ type GenerateFn = (req: GenerateRequest) => Promise<GenerateResponse>;
50
+ /** Settings controlling the loop. */
51
+ interface LoopOptions {
52
+ /** Maximum iterations; -1 means unlimited. Default 10. (FR-012b) */
53
+ maxIterations?: number;
54
+ /** Per-tool-call timeout in ms. (FR-012c) */
55
+ toolTimeoutMs?: number;
56
+ /** Abort signal. */
57
+ signal?: AbortSignal;
58
+ }
59
+ /** Result of running the loop. */
60
+ interface LoopResult {
61
+ messages: Message[];
62
+ final: GenerateResponse;
63
+ status: RunStatus;
64
+ }
65
+ /**
66
+ * Execute the tool-call loop against a generate function and tool registry.
67
+ *
68
+ * @param generate - Produces a model response (typically the middleware pipeline).
69
+ * @param registry - Tools available to the agent (may be empty).
70
+ * @param messages - Initial conversation (system + user, etc.).
71
+ * @param options - Loop tuning.
72
+ */
73
+ declare function runLoop(generate: GenerateFn, registry: ToolRegistry, messages: Message[], options?: LoopOptions): Promise<LoopResult>;
74
+ /** Build the initial message list from instructions + input. */
75
+ declare function buildMessages(instructions: string, input: Message[]): Message[];
76
+
77
+ /**
78
+ * The agent: a configured actor that runs against a provider, optionally using
79
+ * tools and skills, with streaming, reasoning output, multimodal input gating,
80
+ * conversation threads with compaction, and a middleware pipeline.
81
+ *
82
+ * @packageDocumentation
83
+ */
84
+
85
+ /** Configuration for {@link createAgent}. */
86
+ interface AgentConfig {
87
+ name: string;
88
+ instructions: string;
89
+ provider: Provider;
90
+ tools?: Tool[];
91
+ skills?: Skill[];
92
+ /** Max tool-call iterations per run; -1 = unlimited. Default 10. (FR-012b) */
93
+ maxIterations?: number;
94
+ /** Per-tool-call timeout in ms. (FR-012c) */
95
+ toolTimeoutMs?: number;
96
+ /** Compaction threshold as a fraction of maxInputTokens. Default 0.9. (FR-004a) */
97
+ compactionThreshold?: number;
98
+ /** Optional override model for compaction summaries. (FR-004b) */
99
+ compactionModel?: Provider;
100
+ /** Middleware applied around provider calls. (FR-023) */
101
+ middleware?: Middleware[];
102
+ }
103
+ /** Options for a single run. */
104
+ interface RunOptions {
105
+ /** Continue an existing conversation. (FR-004) */
106
+ thread?: Thread;
107
+ /** Abort signal. */
108
+ signal?: AbortSignal;
109
+ }
110
+ /** The result of a non-streaming run. */
111
+ interface RunResult {
112
+ output: string;
113
+ /** Reasoning content — only for reasoning-capable models. (FR-003a) */
114
+ reasoning?: string;
115
+ status: RunStatus;
116
+ /** True when the run was interrupted before completing. (FR-003b) */
117
+ partial: boolean;
118
+ error?: ProviderError;
119
+ /** The thread used/updated by this run. */
120
+ thread: Thread;
121
+ }
122
+ /** Streamed run chunk. */
123
+ type RunChunk = {
124
+ type: "text";
125
+ text: string;
126
+ } | {
127
+ type: "reasoning";
128
+ text: string;
129
+ } | {
130
+ type: "done";
131
+ result: RunResult;
132
+ };
133
+ /** Agent input: plain text or structured (multimodal) messages. (FR-002) */
134
+ type AgentInput = string | Message | Message[];
135
+ /** A runnable agent. */
136
+ interface Agent {
137
+ readonly name: string;
138
+ run(input: AgentInput, opts?: RunOptions): Promise<RunResult>;
139
+ runStream(input: AgentInput, opts?: RunOptions): AsyncIterable<RunChunk>;
140
+ }
141
+ /**
142
+ * Create an agent.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * const agent = createAgent({ name: "Helper", instructions: "Be concise.", provider });
147
+ * const res = await agent.run("Say hello.");
148
+ * console.log(res.status, res.output);
149
+ * ```
150
+ */
151
+ declare function createAgent(config: AgentConfig): Agent;
152
+
153
+ export { type Agent as A, type GenerateFn as G, type LoopOptions as L, type Middleware as M, type Next as N, type RunChunk as R, type AgentConfig as a, type AgentInput as b, type LoopResult as c, type MiddlewareContext as d, type RunOptions as e, type RunResult as f, type RunStatus as g, buildMessages as h, composeMiddleware as i, createAgent as j, runLoop as r };
@@ -0,0 +1,153 @@
1
+ import { M as Message } from './types-Cn1g9Tg4.cjs';
2
+ import { P as ProviderError } from './errors-CjVz4W_5.cjs';
3
+ import { a as GenerateRequest, b as GenerateResponse, P as Provider } from './provider-CMAymr1b.cjs';
4
+ import { T as Tool } from './tool-BZg_znMZ.cjs';
5
+ import { S as Skill } from './skill-DfNChtJN.cjs';
6
+ import { T as Thread } from './thread-Dfo9LLf7.cjs';
7
+ import { T as ToolRegistry } from './registry-D4fThGiN.cjs';
8
+
9
+ /**
10
+ * Middleware pipeline for intercepting and processing agent provider calls —
11
+ * request/response transformation, custom pipelines, and error handling. (FR-023)
12
+ *
13
+ * @packageDocumentation
14
+ */
15
+
16
+ /** Context passed through the middleware chain for one provider call. */
17
+ interface MiddlewareContext {
18
+ /** The agent's name. */
19
+ agentName: string;
20
+ /** The outgoing request (may be mutated by middleware). */
21
+ request: GenerateRequest;
22
+ }
23
+ /** Continue to the next middleware (or the provider call itself). */
24
+ type Next = () => Promise<GenerateResponse>;
25
+ /** A pipeline interceptor. */
26
+ interface Middleware {
27
+ name: string;
28
+ handle(ctx: MiddlewareContext, next: Next): Promise<GenerateResponse>;
29
+ }
30
+ /**
31
+ * Compose middleware into a single function wrapping `core`.
32
+ *
33
+ * @param middleware - Ordered interceptors (first runs outermost).
34
+ * @param core - The terminal operation (the actual provider call).
35
+ */
36
+ declare function composeMiddleware(middleware: Middleware[], core: (ctx: MiddlewareContext) => Promise<GenerateResponse>): (ctx: MiddlewareContext) => Promise<GenerateResponse>;
37
+
38
+ /**
39
+ * The agent run loop: drives provider calls, executes requested tool calls,
40
+ * feeds typed results (including errors, for self-correction) back to the model,
41
+ * and stops on a final answer, the iteration cap, or an abort. (FR-011a, FR-012b)
42
+ *
43
+ * @packageDocumentation
44
+ */
45
+
46
+ /** Outcome status of a run. */
47
+ type RunStatus = "completed" | "failed" | "incomplete" | "limit-exceeded";
48
+ /** A function that produces a model response (optionally through middleware). */
49
+ type GenerateFn = (req: GenerateRequest) => Promise<GenerateResponse>;
50
+ /** Settings controlling the loop. */
51
+ interface LoopOptions {
52
+ /** Maximum iterations; -1 means unlimited. Default 10. (FR-012b) */
53
+ maxIterations?: number;
54
+ /** Per-tool-call timeout in ms. (FR-012c) */
55
+ toolTimeoutMs?: number;
56
+ /** Abort signal. */
57
+ signal?: AbortSignal;
58
+ }
59
+ /** Result of running the loop. */
60
+ interface LoopResult {
61
+ messages: Message[];
62
+ final: GenerateResponse;
63
+ status: RunStatus;
64
+ }
65
+ /**
66
+ * Execute the tool-call loop against a generate function and tool registry.
67
+ *
68
+ * @param generate - Produces a model response (typically the middleware pipeline).
69
+ * @param registry - Tools available to the agent (may be empty).
70
+ * @param messages - Initial conversation (system + user, etc.).
71
+ * @param options - Loop tuning.
72
+ */
73
+ declare function runLoop(generate: GenerateFn, registry: ToolRegistry, messages: Message[], options?: LoopOptions): Promise<LoopResult>;
74
+ /** Build the initial message list from instructions + input. */
75
+ declare function buildMessages(instructions: string, input: Message[]): Message[];
76
+
77
+ /**
78
+ * The agent: a configured actor that runs against a provider, optionally using
79
+ * tools and skills, with streaming, reasoning output, multimodal input gating,
80
+ * conversation threads with compaction, and a middleware pipeline.
81
+ *
82
+ * @packageDocumentation
83
+ */
84
+
85
+ /** Configuration for {@link createAgent}. */
86
+ interface AgentConfig {
87
+ name: string;
88
+ instructions: string;
89
+ provider: Provider;
90
+ tools?: Tool[];
91
+ skills?: Skill[];
92
+ /** Max tool-call iterations per run; -1 = unlimited. Default 10. (FR-012b) */
93
+ maxIterations?: number;
94
+ /** Per-tool-call timeout in ms. (FR-012c) */
95
+ toolTimeoutMs?: number;
96
+ /** Compaction threshold as a fraction of maxInputTokens. Default 0.9. (FR-004a) */
97
+ compactionThreshold?: number;
98
+ /** Optional override model for compaction summaries. (FR-004b) */
99
+ compactionModel?: Provider;
100
+ /** Middleware applied around provider calls. (FR-023) */
101
+ middleware?: Middleware[];
102
+ }
103
+ /** Options for a single run. */
104
+ interface RunOptions {
105
+ /** Continue an existing conversation. (FR-004) */
106
+ thread?: Thread;
107
+ /** Abort signal. */
108
+ signal?: AbortSignal;
109
+ }
110
+ /** The result of a non-streaming run. */
111
+ interface RunResult {
112
+ output: string;
113
+ /** Reasoning content — only for reasoning-capable models. (FR-003a) */
114
+ reasoning?: string;
115
+ status: RunStatus;
116
+ /** True when the run was interrupted before completing. (FR-003b) */
117
+ partial: boolean;
118
+ error?: ProviderError;
119
+ /** The thread used/updated by this run. */
120
+ thread: Thread;
121
+ }
122
+ /** Streamed run chunk. */
123
+ type RunChunk = {
124
+ type: "text";
125
+ text: string;
126
+ } | {
127
+ type: "reasoning";
128
+ text: string;
129
+ } | {
130
+ type: "done";
131
+ result: RunResult;
132
+ };
133
+ /** Agent input: plain text or structured (multimodal) messages. (FR-002) */
134
+ type AgentInput = string | Message | Message[];
135
+ /** A runnable agent. */
136
+ interface Agent {
137
+ readonly name: string;
138
+ run(input: AgentInput, opts?: RunOptions): Promise<RunResult>;
139
+ runStream(input: AgentInput, opts?: RunOptions): AsyncIterable<RunChunk>;
140
+ }
141
+ /**
142
+ * Create an agent.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * const agent = createAgent({ name: "Helper", instructions: "Be concise.", provider });
147
+ * const res = await agent.run("Say hello.");
148
+ * console.log(res.status, res.output);
149
+ * ```
150
+ */
151
+ declare function createAgent(config: AgentConfig): Agent;
152
+
153
+ export { type Agent as A, type GenerateFn as G, type LoopOptions as L, type Middleware as M, type Next as N, type RunChunk as R, type AgentConfig as a, type AgentInput as b, type LoopResult as c, type MiddlewareContext as d, type RunOptions as e, type RunResult as f, type RunStatus as g, buildMessages as h, composeMiddleware as i, createAgent as j, runLoop as r };
package/dist/index.cjs ADDED
@@ -0,0 +1,236 @@
1
+ 'use strict';
2
+
3
+ var chunkIU3LS5FC_cjs = require('./chunk-IU3LS5FC.cjs');
4
+ var chunkRZP2ZUUX_cjs = require('./chunk-RZP2ZUUX.cjs');
5
+ require('./chunk-5M6ER4ZX.cjs');
6
+ var chunkYKZJRE32_cjs = require('./chunk-YKZJRE32.cjs');
7
+ var chunkYBFLWRO5_cjs = require('./chunk-YBFLWRO5.cjs');
8
+ var chunkWSMYH2IN_cjs = require('./chunk-WSMYH2IN.cjs');
9
+ var chunkTAMJ5HSR_cjs = require('./chunk-TAMJ5HSR.cjs');
10
+ var chunkGYDY3KX5_cjs = require('./chunk-GYDY3KX5.cjs');
11
+ var chunkKEI3EALJ_cjs = require('./chunk-KEI3EALJ.cjs');
12
+ var chunkFSDMBWQV_cjs = require('./chunk-FSDMBWQV.cjs');
13
+ var chunkV6O6SYAN_cjs = require('./chunk-V6O6SYAN.cjs');
14
+ var chunkQJ5XHA6S_cjs = require('./chunk-QJ5XHA6S.cjs');
15
+ var chunkLMN75W3W_cjs = require('./chunk-LMN75W3W.cjs');
16
+ var chunkFOTCUNP5_cjs = require('./chunk-FOTCUNP5.cjs');
17
+ var chunkTLACSVEZ_cjs = require('./chunk-TLACSVEZ.cjs');
18
+ var chunkMQ2XTH3S_cjs = require('./chunk-MQ2XTH3S.cjs');
19
+ var chunkIJASUMIQ_cjs = require('./chunk-IJASUMIQ.cjs');
20
+
21
+
22
+
23
+ Object.defineProperty(exports, "defineTool", {
24
+ enumerable: true,
25
+ get: function () { return chunkIU3LS5FC_cjs.defineTool; }
26
+ });
27
+ Object.defineProperty(exports, "CHECKPOINT_VERSION", {
28
+ enumerable: true,
29
+ get: function () { return chunkRZP2ZUUX_cjs.CHECKPOINT_VERSION; }
30
+ });
31
+ Object.defineProperty(exports, "createCheckpoint", {
32
+ enumerable: true,
33
+ get: function () { return chunkRZP2ZUUX_cjs.createCheckpoint; }
34
+ });
35
+ Object.defineProperty(exports, "createWorkflow", {
36
+ enumerable: true,
37
+ get: function () { return chunkRZP2ZUUX_cjs.createWorkflow; }
38
+ });
39
+ Object.defineProperty(exports, "restoreCheckpoint", {
40
+ enumerable: true,
41
+ get: function () { return chunkRZP2ZUUX_cjs.restoreCheckpoint; }
42
+ });
43
+ Object.defineProperty(exports, "runBounded", {
44
+ enumerable: true,
45
+ get: function () { return chunkRZP2ZUUX_cjs.runBounded; }
46
+ });
47
+ Object.defineProperty(exports, "serializeCheckpoint", {
48
+ enumerable: true,
49
+ get: function () { return chunkRZP2ZUUX_cjs.serializeCheckpoint; }
50
+ });
51
+ Object.defineProperty(exports, "stepConcurrent", {
52
+ enumerable: true,
53
+ get: function () { return chunkRZP2ZUUX_cjs.stepConcurrent; }
54
+ });
55
+ Object.defineProperty(exports, "stepGroup", {
56
+ enumerable: true,
57
+ get: function () { return chunkRZP2ZUUX_cjs.stepGroup; }
58
+ });
59
+ Object.defineProperty(exports, "stepHandoff", {
60
+ enumerable: true,
61
+ get: function () { return chunkRZP2ZUUX_cjs.stepHandoff; }
62
+ });
63
+ Object.defineProperty(exports, "stepSequential", {
64
+ enumerable: true,
65
+ get: function () { return chunkRZP2ZUUX_cjs.stepSequential; }
66
+ });
67
+ Object.defineProperty(exports, "loadAgentDefinition", {
68
+ enumerable: true,
69
+ get: function () { return chunkYKZJRE32_cjs.loadAgentDefinition; }
70
+ });
71
+ Object.defineProperty(exports, "buildMessages", {
72
+ enumerable: true,
73
+ get: function () { return chunkYBFLWRO5_cjs.buildMessages; }
74
+ });
75
+ Object.defineProperty(exports, "createAgent", {
76
+ enumerable: true,
77
+ get: function () { return chunkYBFLWRO5_cjs.createAgent; }
78
+ });
79
+ Object.defineProperty(exports, "runLoop", {
80
+ enumerable: true,
81
+ get: function () { return chunkYBFLWRO5_cjs.runLoop; }
82
+ });
83
+ Object.defineProperty(exports, "SkillIndex", {
84
+ enumerable: true,
85
+ get: function () { return chunkWSMYH2IN_cjs.SkillIndex; }
86
+ });
87
+ Object.defineProperty(exports, "defineSkill", {
88
+ enumerable: true,
89
+ get: function () { return chunkWSMYH2IN_cjs.defineSkill; }
90
+ });
91
+ Object.defineProperty(exports, "loadSource", {
92
+ enumerable: true,
93
+ get: function () { return chunkWSMYH2IN_cjs.loadSource; }
94
+ });
95
+ Object.defineProperty(exports, "ToolRegistry", {
96
+ enumerable: true,
97
+ get: function () { return chunkTAMJ5HSR_cjs.ToolRegistry; }
98
+ });
99
+ Object.defineProperty(exports, "namespacedName", {
100
+ enumerable: true,
101
+ get: function () { return chunkTAMJ5HSR_cjs.namespacedName; }
102
+ });
103
+ Object.defineProperty(exports, "validateArgs", {
104
+ enumerable: true,
105
+ get: function () { return chunkTAMJ5HSR_cjs.validateArgs; }
106
+ });
107
+ Object.defineProperty(exports, "connectMCP", {
108
+ enumerable: true,
109
+ get: function () { return chunkGYDY3KX5_cjs.connectMCP; }
110
+ });
111
+ Object.defineProperty(exports, "mcpToolToTool", {
112
+ enumerable: true,
113
+ get: function () { return chunkGYDY3KX5_cjs.mcpToolToTool; }
114
+ });
115
+ Object.defineProperty(exports, "useMiddleware", {
116
+ enumerable: true,
117
+ get: function () { return chunkKEI3EALJ_cjs.useMiddleware; }
118
+ });
119
+ Object.defineProperty(exports, "composeMiddleware", {
120
+ enumerable: true,
121
+ get: function () { return chunkFSDMBWQV_cjs.composeMiddleware; }
122
+ });
123
+ Object.defineProperty(exports, "configureObservability", {
124
+ enumerable: true,
125
+ get: function () { return chunkV6O6SYAN_cjs.configureObservability; }
126
+ });
127
+ Object.defineProperty(exports, "isObservabilityEnabled", {
128
+ enumerable: true,
129
+ get: function () { return chunkV6O6SYAN_cjs.isObservabilityEnabled; }
130
+ });
131
+ Object.defineProperty(exports, "resetObservability", {
132
+ enumerable: true,
133
+ get: function () { return chunkV6O6SYAN_cjs.resetObservability; }
134
+ });
135
+ Object.defineProperty(exports, "withSpan", {
136
+ enumerable: true,
137
+ get: function () { return chunkV6O6SYAN_cjs.withSpan; }
138
+ });
139
+ Object.defineProperty(exports, "ThreadPersistence", {
140
+ enumerable: true,
141
+ get: function () { return chunkQJ5XHA6S_cjs.ThreadPersistence; }
142
+ });
143
+ Object.defineProperty(exports, "createBrowserStore", {
144
+ enumerable: true,
145
+ get: function () { return chunkQJ5XHA6S_cjs.createBrowserStore; }
146
+ });
147
+ Object.defineProperty(exports, "createMemoryStore", {
148
+ enumerable: true,
149
+ get: function () { return chunkQJ5XHA6S_cjs.createMemoryStore; }
150
+ });
151
+ Object.defineProperty(exports, "Thread", {
152
+ enumerable: true,
153
+ get: function () { return chunkLMN75W3W_cjs.Thread; }
154
+ });
155
+ Object.defineProperty(exports, "estimateTokens", {
156
+ enumerable: true,
157
+ get: function () { return chunkLMN75W3W_cjs.estimateTokens; }
158
+ });
159
+ Object.defineProperty(exports, "hasImage", {
160
+ enumerable: true,
161
+ get: function () { return chunkLMN75W3W_cjs.hasImage; }
162
+ });
163
+ Object.defineProperty(exports, "messageText", {
164
+ enumerable: true,
165
+ get: function () { return chunkLMN75W3W_cjs.messageText; }
166
+ });
167
+ Object.defineProperty(exports, "textMessage", {
168
+ enumerable: true,
169
+ get: function () { return chunkLMN75W3W_cjs.textMessage; }
170
+ });
171
+ Object.defineProperty(exports, "detectRuntime", {
172
+ enumerable: true,
173
+ get: function () { return chunkFOTCUNP5_cjs.detectRuntime; }
174
+ });
175
+ Object.defineProperty(exports, "requireCapability", {
176
+ enumerable: true,
177
+ get: function () { return chunkFOTCUNP5_cjs.requireCapability; }
178
+ });
179
+ Object.defineProperty(exports, "resetRuntimeCache", {
180
+ enumerable: true,
181
+ get: function () { return chunkFOTCUNP5_cjs.resetRuntimeCache; }
182
+ });
183
+ Object.defineProperty(exports, "createCopilotProvider", {
184
+ enumerable: true,
185
+ get: function () { return chunkTLACSVEZ_cjs.createCopilotProvider; }
186
+ });
187
+ Object.defineProperty(exports, "createOpenAICompatibleProvider", {
188
+ enumerable: true,
189
+ get: function () { return chunkTLACSVEZ_cjs.createOpenAICompatibleProvider; }
190
+ });
191
+ Object.defineProperty(exports, "providerErrorFromStatus", {
192
+ enumerable: true,
193
+ get: function () { return chunkTLACSVEZ_cjs.providerErrorFromStatus; }
194
+ });
195
+ Object.defineProperty(exports, "withRetry", {
196
+ enumerable: true,
197
+ get: function () { return chunkTLACSVEZ_cjs.withRetry; }
198
+ });
199
+ Object.defineProperty(exports, "CheckpointError", {
200
+ enumerable: true,
201
+ get: function () { return chunkMQ2XTH3S_cjs.CheckpointError; }
202
+ });
203
+ Object.defineProperty(exports, "FrameworkError", {
204
+ enumerable: true,
205
+ get: function () { return chunkMQ2XTH3S_cjs.FrameworkError; }
206
+ });
207
+ Object.defineProperty(exports, "MCPError", {
208
+ enumerable: true,
209
+ get: function () { return chunkMQ2XTH3S_cjs.MCPError; }
210
+ });
211
+ Object.defineProperty(exports, "ProviderError", {
212
+ enumerable: true,
213
+ get: function () { return chunkMQ2XTH3S_cjs.ProviderError; }
214
+ });
215
+ Object.defineProperty(exports, "RuntimeUnsupportedError", {
216
+ enumerable: true,
217
+ get: function () { return chunkMQ2XTH3S_cjs.RuntimeUnsupportedError; }
218
+ });
219
+ Object.defineProperty(exports, "ToolError", {
220
+ enumerable: true,
221
+ get: function () { return chunkMQ2XTH3S_cjs.ToolError; }
222
+ });
223
+ Object.defineProperty(exports, "ValidationError", {
224
+ enumerable: true,
225
+ get: function () { return chunkMQ2XTH3S_cjs.ValidationError; }
226
+ });
227
+ Object.defineProperty(exports, "REDACTED", {
228
+ enumerable: true,
229
+ get: function () { return chunkIJASUMIQ_cjs.REDACTED; }
230
+ });
231
+ Object.defineProperty(exports, "redact", {
232
+ enumerable: true,
233
+ get: function () { return chunkIJASUMIQ_cjs.redact; }
234
+ });
235
+ //# sourceMappingURL=index.cjs.map
236
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}