@chatcops/core 0.3.2 → 0.5.0

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 (162) hide show
  1. package/dist/agent/chat.d.ts +13 -0
  2. package/dist/agent/chat.d.ts.map +1 -0
  3. package/dist/agent/chat.js +42 -0
  4. package/dist/agent/chat.js.map +1 -0
  5. package/dist/agent/errors.d.ts +14 -0
  6. package/dist/agent/errors.d.ts.map +1 -0
  7. package/dist/agent/errors.js +24 -0
  8. package/dist/agent/errors.js.map +1 -0
  9. package/dist/agent/index.d.ts +5 -0
  10. package/dist/agent/index.d.ts.map +1 -0
  11. package/dist/agent/index.js +5 -0
  12. package/dist/agent/index.js.map +1 -0
  13. package/dist/agent/run-turn.d.ts +68 -0
  14. package/dist/agent/run-turn.d.ts.map +1 -0
  15. package/dist/agent/run-turn.js +344 -0
  16. package/dist/agent/run-turn.js.map +1 -0
  17. package/dist/agent/tool-registry.d.ts +28 -0
  18. package/dist/agent/tool-registry.d.ts.map +1 -0
  19. package/dist/agent/tool-registry.js +69 -0
  20. package/dist/agent/tool-registry.js.map +1 -0
  21. package/dist/analytics/index.d.ts +1 -0
  22. package/dist/analytics/index.d.ts.map +1 -1
  23. package/dist/analytics/index.js +1 -0
  24. package/dist/analytics/index.js.map +1 -1
  25. package/dist/analytics/sink.d.ts +24 -0
  26. package/dist/analytics/sink.d.ts.map +1 -0
  27. package/dist/analytics/sink.js +106 -0
  28. package/dist/analytics/sink.js.map +1 -0
  29. package/dist/conversation/index.d.ts +1 -0
  30. package/dist/conversation/index.d.ts.map +1 -1
  31. package/dist/conversation/index.js.map +1 -1
  32. package/dist/conversation/manager.d.ts +62 -6
  33. package/dist/conversation/manager.d.ts.map +1 -1
  34. package/dist/conversation/manager.js +109 -30
  35. package/dist/conversation/manager.js.map +1 -1
  36. package/dist/conversation/store.d.ts +6 -5
  37. package/dist/conversation/store.d.ts.map +1 -1
  38. package/dist/conversation/store.js +4 -0
  39. package/dist/conversation/store.js.map +1 -1
  40. package/dist/index.d.ts +18 -4
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +14 -2
  43. package/dist/index.js.map +1 -1
  44. package/dist/limits/budget.d.ts +84 -0
  45. package/dist/limits/budget.d.ts.map +1 -0
  46. package/dist/limits/budget.js +114 -0
  47. package/dist/limits/budget.js.map +1 -0
  48. package/dist/limits/rate-limit.d.ts +53 -0
  49. package/dist/limits/rate-limit.d.ts.map +1 -0
  50. package/dist/limits/rate-limit.js +68 -0
  51. package/dist/limits/rate-limit.js.map +1 -0
  52. package/dist/parts.d.ts +9 -0
  53. package/dist/parts.d.ts.map +1 -0
  54. package/dist/parts.js +17 -0
  55. package/dist/parts.js.map +1 -0
  56. package/dist/protocol/ai-sdk.d.ts +27 -0
  57. package/dist/protocol/ai-sdk.d.ts.map +1 -0
  58. package/dist/protocol/ai-sdk.js +127 -0
  59. package/dist/protocol/ai-sdk.js.map +1 -0
  60. package/dist/protocol/errors.d.ts +10 -0
  61. package/dist/protocol/errors.d.ts.map +1 -0
  62. package/dist/protocol/errors.js +42 -0
  63. package/dist/protocol/errors.js.map +1 -0
  64. package/dist/protocol/index.d.ts +9 -0
  65. package/dist/protocol/index.d.ts.map +1 -0
  66. package/dist/protocol/index.js +6 -0
  67. package/dist/protocol/index.js.map +1 -0
  68. package/dist/protocol/legacy.d.ts +18 -0
  69. package/dist/protocol/legacy.d.ts.map +1 -0
  70. package/dist/protocol/legacy.js +41 -0
  71. package/dist/protocol/legacy.js.map +1 -0
  72. package/dist/protocol/sse.d.ts +10 -0
  73. package/dist/protocol/sse.d.ts.map +1 -0
  74. package/dist/protocol/sse.js +15 -0
  75. package/dist/protocol/sse.js.map +1 -0
  76. package/dist/protocol/v1.d.ts +140 -0
  77. package/dist/protocol/v1.d.ts.map +1 -0
  78. package/dist/protocol/v1.js +15 -0
  79. package/dist/protocol/v1.js.map +1 -0
  80. package/dist/providers/base.d.ts +17 -15
  81. package/dist/providers/base.d.ts.map +1 -1
  82. package/dist/providers/base.js +43 -31
  83. package/dist/providers/base.js.map +1 -1
  84. package/dist/providers/claude.d.ts +40 -2
  85. package/dist/providers/claude.d.ts.map +1 -1
  86. package/dist/providers/claude.js +250 -113
  87. package/dist/providers/claude.js.map +1 -1
  88. package/dist/providers/gemini.d.ts +23 -3
  89. package/dist/providers/gemini.d.ts.map +1 -1
  90. package/dist/providers/gemini.js +245 -102
  91. package/dist/providers/gemini.js.map +1 -1
  92. package/dist/providers/history.d.ts +52 -0
  93. package/dist/providers/history.d.ts.map +1 -0
  94. package/dist/providers/history.js +212 -0
  95. package/dist/providers/history.js.map +1 -0
  96. package/dist/providers/index.d.ts +5 -5
  97. package/dist/providers/index.d.ts.map +1 -1
  98. package/dist/providers/index.js +5 -4
  99. package/dist/providers/index.js.map +1 -1
  100. package/dist/providers/openai.d.ts +37 -3
  101. package/dist/providers/openai.d.ts.map +1 -1
  102. package/dist/providers/openai.js +246 -140
  103. package/dist/providers/openai.js.map +1 -1
  104. package/dist/providers/registry.d.ts +7 -0
  105. package/dist/providers/registry.d.ts.map +1 -0
  106. package/dist/providers/registry.js +12 -0
  107. package/dist/providers/registry.js.map +1 -0
  108. package/dist/providers/schema.d.ts +16 -0
  109. package/dist/providers/schema.d.ts.map +1 -0
  110. package/dist/providers/schema.js +80 -0
  111. package/dist/providers/schema.js.map +1 -0
  112. package/dist/providers/tool-execution.d.ts +10 -0
  113. package/dist/providers/tool-execution.d.ts.map +1 -1
  114. package/dist/providers/tool-execution.js +38 -12
  115. package/dist/providers/tool-execution.js.map +1 -1
  116. package/dist/providers/types.d.ts +71 -0
  117. package/dist/providers/types.d.ts.map +1 -0
  118. package/dist/providers/types.js +2 -0
  119. package/dist/providers/types.js.map +1 -0
  120. package/dist/storage/adapt.d.ts +15 -0
  121. package/dist/storage/adapt.d.ts.map +1 -0
  122. package/dist/storage/adapt.js +83 -0
  123. package/dist/storage/adapt.js.map +1 -0
  124. package/dist/storage/errors.d.ts +18 -0
  125. package/dist/storage/errors.d.ts.map +1 -0
  126. package/dist/storage/errors.js +28 -0
  127. package/dist/storage/errors.js.map +1 -0
  128. package/dist/storage/index.d.ts +5 -0
  129. package/dist/storage/index.d.ts.map +1 -0
  130. package/dist/storage/index.js +4 -0
  131. package/dist/storage/index.js.map +1 -0
  132. package/dist/storage/memory.d.ts +24 -0
  133. package/dist/storage/memory.d.ts.map +1 -0
  134. package/dist/storage/memory.js +265 -0
  135. package/dist/storage/memory.js.map +1 -0
  136. package/dist/storage/types.d.ts +118 -0
  137. package/dist/storage/types.d.ts.map +1 -0
  138. package/dist/storage/types.js +2 -0
  139. package/dist/storage/types.js.map +1 -0
  140. package/dist/testing/conformance.d.ts +29 -0
  141. package/dist/testing/conformance.d.ts.map +1 -0
  142. package/dist/testing/conformance.js +335 -0
  143. package/dist/testing/conformance.js.map +1 -0
  144. package/dist/testing/index.d.ts +3 -0
  145. package/dist/testing/index.d.ts.map +1 -0
  146. package/dist/testing/index.js +5 -0
  147. package/dist/testing/index.js.map +1 -0
  148. package/dist/testing/provider.d.ts +45 -0
  149. package/dist/testing/provider.d.ts.map +1 -0
  150. package/dist/testing/provider.js +82 -0
  151. package/dist/testing/provider.js.map +1 -0
  152. package/dist/tools/base.d.ts +14 -4
  153. package/dist/tools/base.d.ts.map +1 -1
  154. package/dist/tools/base.js +4 -2
  155. package/dist/tools/base.js.map +1 -1
  156. package/dist/tools/lead-capture.d.ts +3 -1
  157. package/dist/tools/lead-capture.d.ts.map +1 -1
  158. package/dist/tools/lead-capture.js +6 -1
  159. package/dist/tools/lead-capture.js.map +1 -1
  160. package/dist/types.d.ts +168 -4
  161. package/dist/types.d.ts.map +1 -1
  162. package/package.json +53 -5
@@ -0,0 +1,13 @@
1
+ import type { AIProvider } from '../providers/types.js';
2
+ import type { ProviderChatParams } from '../types.js';
3
+ type SteppingProvider = AIProvider & Required<Pick<AIProvider, 'step'>>;
4
+ /**
5
+ * `chat()` for providers that have `step()`: runs a turn and yields its text.
6
+ * Errors throw, as they did before turns existed: a refusal, the tool round
7
+ * limit, a provider error, and an abort.
8
+ */
9
+ export declare function chatViaTurn(provider: SteppingProvider, params: ProviderChatParams): AsyncGenerator<string>;
10
+ /** `chatSync()` on top of `chat()`: the whole reply as one string. */
11
+ export declare function chatSyncViaTurn(provider: SteppingProvider, params: ProviderChatParams): Promise<string>;
12
+ export {};
13
+ //# sourceMappingURL=chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/agent/chat.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAItD,KAAK,gBAAgB,GAAG,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;AAExE;;;;GAIG;AACH,wBAAuB,WAAW,CAAC,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,kBAAkB,GAAG,cAAc,CAAC,MAAM,CAAC,CAyBjH;AAED,sEAAsE;AACtE,wBAAsB,eAAe,CAAC,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAI7G"}
@@ -0,0 +1,42 @@
1
+ import { MAX_TOOL_ROUNDS } from '../providers/tool-execution.js';
2
+ import { runTurn } from './run-turn.js';
3
+ import { executorRegistry } from './tool-registry.js';
4
+ /**
5
+ * `chat()` for providers that have `step()`: runs a turn and yields its text.
6
+ * Errors throw, as they did before turns existed: a refusal, the tool round
7
+ * limit, a provider error, and an abort.
8
+ */
9
+ export async function* chatViaTurn(provider, params) {
10
+ const turn = runTurn({
11
+ provider,
12
+ messages: params.messages,
13
+ systemPrompt: params.systemPrompt,
14
+ tools: executorRegistry(params.tools, params.toolExecutor),
15
+ conversationId: '',
16
+ maxSteps: MAX_TOOL_ROUNDS + 1,
17
+ toolTimeoutMs: params.toolTimeoutMs,
18
+ maxTokens: params.maxTokens,
19
+ temperature: params.temperature,
20
+ signal: params.signal,
21
+ });
22
+ let next = await turn.next();
23
+ while (!next.done) {
24
+ if (next.value.type === 'text-delta')
25
+ yield next.value.delta;
26
+ next = await turn.next();
27
+ }
28
+ const result = next.value;
29
+ if (result.status === 'aborted') {
30
+ throw params.signal?.reason ?? new DOMException('The operation was aborted.', 'AbortError');
31
+ }
32
+ if (result.error !== undefined)
33
+ throw result.error;
34
+ }
35
+ /** `chatSync()` on top of `chat()`: the whole reply as one string. */
36
+ export async function chatSyncViaTurn(provider, params) {
37
+ let text = '';
38
+ for await (const chunk of chatViaTurn(provider, params))
39
+ text += chunk;
40
+ return text;
41
+ }
42
+ //# sourceMappingURL=chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/agent/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGjE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD;;;;GAIG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,WAAW,CAAC,QAA0B,EAAE,MAA0B;IACvF,MAAM,IAAI,GAAG,OAAO,CAAC;QACnB,QAAQ;QACR,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC;QAC1D,cAAc,EAAE,EAAE;QAClB,QAAQ,EAAE,eAAe,GAAG,CAAC;QAC7B,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAC,CAAC;IAEH,IAAI,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;IAC7B,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,YAAY;YAAE,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;QAC7D,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;IAC1B,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,IAAI,YAAY,CAAC,4BAA4B,EAAE,YAAY,CAAC,CAAC;IAC9F,CAAC;IACD,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS;QAAE,MAAM,MAAM,CAAC,KAAK,CAAC;AACrD,CAAC;AAED,sEAAsE;AACtE,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,QAA0B,EAAE,MAA0B;IAC1F,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC;QAAE,IAAI,IAAI,KAAK,CAAC;IACvE,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,14 @@
1
+ /** The model declined to answer. */
2
+ export declare class RefusalError extends Error {
3
+ constructor();
4
+ }
5
+ /** The provider's safety filter stopped the reply. */
6
+ export declare class ContentFilterError extends Error {
7
+ constructor();
8
+ }
9
+ /** The model kept asking for tools after the last allowed round. */
10
+ export declare class MaxStepsError extends Error {
11
+ readonly toolRounds: number;
12
+ constructor(toolRounds: number);
13
+ }
14
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/agent/errors.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,qBAAa,YAAa,SAAQ,KAAK;;CAKtC;AAED,sDAAsD;AACtD,qBAAa,kBAAmB,SAAQ,KAAK;;CAK5C;AAED,oEAAoE;AACpE,qBAAa,aAAc,SAAQ,KAAK;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM;gBAAlB,UAAU,EAAE,MAAM;CAIxC"}
@@ -0,0 +1,24 @@
1
+ /** The model declined to answer. */
2
+ export class RefusalError extends Error {
3
+ constructor() {
4
+ super('The model declined to answer this request (refusal).');
5
+ this.name = 'RefusalError';
6
+ }
7
+ }
8
+ /** The provider's safety filter stopped the reply. */
9
+ export class ContentFilterError extends Error {
10
+ constructor() {
11
+ super("The provider's content filter stopped the reply.");
12
+ this.name = 'ContentFilterError';
13
+ }
14
+ }
15
+ /** The model kept asking for tools after the last allowed round. */
16
+ export class MaxStepsError extends Error {
17
+ toolRounds;
18
+ constructor(toolRounds) {
19
+ super(`Exceeded maximum tool rounds (${toolRounds}).`);
20
+ this.toolRounds = toolRounds;
21
+ this.name = 'MaxStepsError';
22
+ }
23
+ }
24
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/agent/errors.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC;QACE,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED,sDAAsD;AACtD,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C;QACE,KAAK,CAAC,kDAAkD,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED,oEAAoE;AACpE,MAAM,OAAO,aAAc,SAAQ,KAAK;IACjB;IAArB,YAAqB,UAAkB;QACrC,KAAK,CAAC,iCAAiC,UAAU,IAAI,CAAC,CAAC;QADpC,eAAU,GAAV,UAAU,CAAQ;QAErC,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export { runTurn, DEFAULT_MAX_STEPS, type RunTurnOptions, type TurnResult } from './run-turn.js';
2
+ export { toolRegistry, executorRegistry, toolOutput, MAX_TOOL_OUTPUT_CHARS, type ToolRegistry, type ToolRunContext, } from './tool-registry.js';
3
+ export { RefusalError, ContentFilterError, MaxStepsError } from './errors.js';
4
+ export { chatViaTurn, chatSyncViaTurn } from './chat.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AACjG,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,qBAAqB,EACrB,KAAK,YAAY,EACjB,KAAK,cAAc,GACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { runTurn, DEFAULT_MAX_STEPS } from './run-turn.js';
2
+ export { toolRegistry, executorRegistry, toolOutput, MAX_TOOL_OUTPUT_CHARS, } from './tool-registry.js';
3
+ export { RefusalError, ContentFilterError, MaxStepsError } from './errors.js';
4
+ export { chatViaTurn, chatSyncViaTurn } from './chat.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAwC,MAAM,eAAe,CAAC;AACjG,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,qBAAqB,GAGtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { type WireFinishReason, type WirePart } from '../protocol/v1.js';
2
+ import type { AIProvider } from '../providers/types.js';
3
+ import type { ChatMessage, MessagePart, TokenUsage } from '../types.js';
4
+ import { type BudgetContext, type BudgetGuard } from '../limits/budget.js';
5
+ import { type ToolRegistry } from './tool-registry.js';
6
+ /** Model requests per turn: five tool rounds and the answer after them, as in 0.5. */
7
+ export declare const DEFAULT_MAX_STEPS = 6;
8
+ export interface RunTurnOptions {
9
+ provider: AIProvider;
10
+ /** The history to send, oldest first, ending with the visitor's message. */
11
+ messages: ChatMessage[];
12
+ systemPrompt: string;
13
+ /** Per-request instructions, sent after the system prompt and outside the cached prefix. */
14
+ systemContext?: string;
15
+ tools?: ToolRegistry;
16
+ conversationId: string;
17
+ /** The id to save the reply under. A new one by default. */
18
+ messageId?: string;
19
+ /** Model requests in this turn, counting the final answer. Default 6. */
20
+ maxSteps?: number;
21
+ toolTimeoutMs?: number;
22
+ maxTokens?: number;
23
+ temperature?: number;
24
+ /** Aborts the turn, for example when the visitor disconnects. */
25
+ signal?: AbortSignal;
26
+ /** Adds token usage to the `finish` part. */
27
+ exposeUsage?: boolean;
28
+ /**
29
+ * Checked before each model request and charged after it. A used-up
30
+ * budget ends the reply with `budget_exceeded`, and the reply length is
31
+ * capped to the tokens left.
32
+ */
33
+ budget?: {
34
+ guard: BudgetGuard;
35
+ context: BudgetContext;
36
+ };
37
+ /**
38
+ * Saves the reply. Called after each tool round with `final: false`, and
39
+ * once at the end with `final: true` and the reply's final status.
40
+ */
41
+ onPersist?(message: ChatMessage, info: {
42
+ final: boolean;
43
+ }): Promise<void> | void;
44
+ /** Called as each tool call, tool result and emitted part (a captured lead) is added. */
45
+ onPart?(part: MessagePart): void;
46
+ }
47
+ export interface TurnResult {
48
+ /** `complete`, or `incomplete` (an error, the token limit, the step limit), or `aborted`. */
49
+ status: NonNullable<ChatMessage['status']>;
50
+ message: ChatMessage;
51
+ usage: TokenUsage;
52
+ finishReason: WireFinishReason;
53
+ /** What went wrong, for `incomplete` turns that ended in an error. */
54
+ error?: unknown;
55
+ }
56
+ /** One system prompt, for providers that take only one. */
57
+ export declare function joinSystem(systemPrompt: string, systemContext?: string): string;
58
+ /**
59
+ * Runs one reply: model steps, tool calls between them, and saving the reply
60
+ * as it grows. Yields protocol v1 parts, starting with `start` and always
61
+ * ending with `finish`, and returns what happened.
62
+ *
63
+ * Provider errors don't throw: they become an `error` part, a `finish` with
64
+ * reason `error`, and `result.error`. An abort ends with reason `aborted`.
65
+ * Only a failing `onPersist` throws.
66
+ */
67
+ export declare function runTurn(options: RunTurnOptions): AsyncGenerator<WirePart, TurnResult>;
68
+ //# sourceMappingURL=run-turn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-turn.d.ts","sourceRoot":"","sources":["../../src/agent/run-turn.ts"],"names":[],"mappings":"AACA,OAAO,EAAwC,KAAK,gBAAgB,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC/G,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EAGX,UAAU,EAIX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAuB,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGhG,OAAO,EAAoB,KAAK,YAAY,EAAc,MAAM,oBAAoB,CAAC;AAErF,sFAAsF;AACtF,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAEnC,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,UAAU,CAAC;IACrB,4EAA4E;IAC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;AACH,wBAAuB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,CAAC,QAAQ,EAAE,UAAU,CAAC,CA6Q5F"}
@@ -0,0 +1,344 @@
1
+ import { messageText } from '../parts.js';
2
+ import { PROTOCOL_VERSION } from '../protocol/v1.js';
3
+ import { BudgetExceededError } from '../limits/budget.js';
4
+ import { DEFAULT_MAX_TOKENS } from '../providers/base.js';
5
+ import { ContentFilterError, MaxStepsError, RefusalError } from './errors.js';
6
+ import { executorRegistry, toolOutput } from './tool-registry.js';
7
+ /** Model requests per turn: five tool rounds and the answer after them, as in 0.5. */
8
+ export const DEFAULT_MAX_STEPS = 6;
9
+ const NO_TOOLS = executorRegistry([]);
10
+ /** One system prompt, for providers that take only one. */
11
+ export function joinSystem(systemPrompt, systemContext) {
12
+ return systemContext ? `${systemPrompt}\n\n${systemContext}` : systemPrompt;
13
+ }
14
+ /** Never ask for fewer output tokens than this, even with little budget left. */
15
+ const MIN_STEP_TOKENS = 256;
16
+ function addUsage(total, step) {
17
+ total.inputTokens += step.inputTokens;
18
+ total.outputTokens += step.outputTokens;
19
+ if (step.cacheReadTokens)
20
+ total.cacheReadTokens = (total.cacheReadTokens ?? 0) + step.cacheReadTokens;
21
+ if (step.cacheWriteTokens)
22
+ total.cacheWriteTokens = (total.cacheWriteTokens ?? 0) + step.cacheWriteTokens;
23
+ }
24
+ /**
25
+ * Signatures only matter within the turn that produced them. Dropping them
26
+ * once the turn is over keeps stored conversations small, and providers
27
+ * accept history without them.
28
+ */
29
+ function withoutReplayData(parts) {
30
+ const out = [];
31
+ for (const part of parts) {
32
+ if (!('providerMetadata' in part) || !part.providerMetadata) {
33
+ out.push(part);
34
+ continue;
35
+ }
36
+ const { claude: _claude, gemini, ...others } = part.providerMetadata;
37
+ const keptGemini = gemini?.syntheticId ? { gemini: { syntheticId: true } } : {};
38
+ const providerMetadata = { ...others, ...keptGemini };
39
+ const { providerMetadata: _, ...rest } = part;
40
+ if (part.type === 'reasoning' && part.text === '')
41
+ continue;
42
+ if (part.type === 'text' && part.text === '')
43
+ continue;
44
+ out.push(Object.keys(providerMetadata).length ? { ...rest, providerMetadata } : rest);
45
+ }
46
+ return out;
47
+ }
48
+ function resultPart(call, result) {
49
+ return {
50
+ type: 'tool-result',
51
+ toolCallId: call.id,
52
+ toolName: call.name,
53
+ output: toolOutput(result),
54
+ ...(result.success ? {} : { error: result.message ?? 'The tool failed.' }),
55
+ };
56
+ }
57
+ function toWire(part) {
58
+ switch (part.type) {
59
+ case 'tool-call':
60
+ return { type: 'tool-call', toolCallId: part.toolCallId, toolName: part.toolName, input: part.input, executor: part.executor };
61
+ case 'tool-result':
62
+ return { type: 'tool-result', toolCallId: part.toolCallId, output: part.output, ...(part.error ? { error: part.error } : {}) };
63
+ case 'lead-captured':
64
+ return { type: 'lead-captured', lead: part.lead };
65
+ case 'source':
66
+ return { type: 'source', sourceId: part.sourceId, url: part.url, ...(part.title ? { title: part.title } : {}), ...(part.snippet ? { snippet: part.snippet } : {}) };
67
+ default:
68
+ return null;
69
+ }
70
+ }
71
+ /**
72
+ * Runs one reply: model steps, tool calls between them, and saving the reply
73
+ * as it grows. Yields protocol v1 parts, starting with `start` and always
74
+ * ending with `finish`, and returns what happened.
75
+ *
76
+ * Provider errors don't throw: they become an `error` part, a `finish` with
77
+ * reason `error`, and `result.error`. An abort ends with reason `aborted`.
78
+ * Only a failing `onPersist` throws.
79
+ */
80
+ export async function* runTurn(options) {
81
+ const { provider, signal } = options;
82
+ const tools = options.tools ?? NO_TOOLS;
83
+ const maxSteps = Math.max(1, options.maxSteps ?? DEFAULT_MAX_STEPS);
84
+ const toolSignal = signal ?? new AbortController().signal;
85
+ const usage = { inputTokens: 0, outputTokens: 0 };
86
+ const message = {
87
+ id: options.messageId ?? crypto.randomUUID(),
88
+ role: 'assistant',
89
+ content: '',
90
+ parts: [],
91
+ timestamp: Date.now(),
92
+ aiGenerated: true,
93
+ };
94
+ const parts = message.parts;
95
+ let textCount = 0;
96
+ const add = (part) => {
97
+ parts.push(part);
98
+ if (part.type !== 'text' && part.type !== 'reasoning')
99
+ options.onPart?.(part);
100
+ return toWire(part);
101
+ };
102
+ const persist = async (final) => {
103
+ message.content = messageText(parts);
104
+ message.usage = { ...usage };
105
+ if (!final)
106
+ message.status = 'incomplete';
107
+ await options.onPersist?.(message, { final });
108
+ };
109
+ async function* end(status, detail = {}) {
110
+ message.status = status;
111
+ message.parts = withoutReplayData(parts);
112
+ if (detail.errorPart)
113
+ yield { type: 'error', ...detail.errorPart };
114
+ const reason = status === 'aborted' ? 'aborted' : detail.errorPart ? 'error' : (detail.reason ?? 'stop');
115
+ message.content = messageText(message.parts);
116
+ message.usage = { ...usage };
117
+ await options.onPersist?.(message, { final: true });
118
+ yield {
119
+ type: 'finish',
120
+ reason,
121
+ ...(options.exposeUsage ? { usage: { inputTokens: usage.inputTokens, outputTokens: usage.outputTokens } } : {}),
122
+ };
123
+ return { status, message, usage, finishReason: reason, ...(detail.error !== undefined ? { error: detail.error } : {}) };
124
+ }
125
+ const failed = (error) => signal?.aborted
126
+ ? end('aborted')
127
+ : end('incomplete', {
128
+ error,
129
+ errorPart: { code: 'provider_error', retryable: true },
130
+ });
131
+ /**
132
+ * Checks the budget before a model request. Ends the turn when one is used
133
+ * up; otherwise resolves the reply length, capped to the tokens left.
134
+ */
135
+ async function* checkBudget(stepNumber) {
136
+ if (!options.budget)
137
+ return { maxTokens: options.maxTokens };
138
+ try {
139
+ const { tokensLeft } = await options.budget.guard.before(options.budget.context, stepNumber);
140
+ if (tokensLeft === undefined)
141
+ return { maxTokens: options.maxTokens };
142
+ const wanted = options.maxTokens ?? DEFAULT_MAX_TOKENS;
143
+ return { maxTokens: Math.min(wanted, Math.max(MIN_STEP_TOKENS, tokensLeft)) };
144
+ }
145
+ catch (error) {
146
+ if (!(error instanceof BudgetExceededError))
147
+ throw error;
148
+ return {
149
+ ended: yield* end('incomplete', {
150
+ error,
151
+ errorPart: { code: 'budget_exceeded', retryable: false, scope: error.scope },
152
+ }),
153
+ };
154
+ }
155
+ }
156
+ yield { type: 'start', protocol: PROTOCOL_VERSION, conversationId: options.conversationId, messageId: message.id };
157
+ if (!provider.step) {
158
+ return yield* legacyTurn();
159
+ }
160
+ const step = provider.step.bind(provider);
161
+ for (let stepNumber = 1;; stepNumber++) {
162
+ let textId = null;
163
+ let finish;
164
+ const calls = [];
165
+ const budget = yield* checkBudget(stepNumber);
166
+ if (budget.ended)
167
+ return budget.ended;
168
+ try {
169
+ signal?.throwIfAborted();
170
+ for await (const event of step({
171
+ messages: [...options.messages, message],
172
+ systemPrompt: options.systemPrompt,
173
+ ...(options.systemContext ? { systemContext: options.systemContext } : {}),
174
+ ...(tools.definitions.length ? { tools: tools.definitions } : {}),
175
+ maxTokens: budget.maxTokens,
176
+ temperature: options.temperature,
177
+ signal,
178
+ })) {
179
+ if (event.type === 'text-delta') {
180
+ if (!event.delta)
181
+ continue;
182
+ if (!textId) {
183
+ textId = `${message.id}-${++textCount}`;
184
+ yield { type: 'text-start', id: textId };
185
+ }
186
+ yield { type: 'text-delta', id: textId, delta: event.delta };
187
+ }
188
+ else if (event.type === 'tool-call') {
189
+ calls.push(event);
190
+ }
191
+ else if (event.type === 'finish') {
192
+ finish = event;
193
+ }
194
+ // Reasoning is kept in the stored parts but never streamed (F01-D5).
195
+ }
196
+ if (!finish)
197
+ throw new Error(`The ${provider.name} step ended without finishing.`);
198
+ }
199
+ catch (error) {
200
+ if (textId)
201
+ yield { type: 'text-end', id: textId };
202
+ return yield* failed(error);
203
+ }
204
+ if (textId)
205
+ yield { type: 'text-end', id: textId };
206
+ addUsage(usage, finish.usage);
207
+ await options.budget?.guard.after(options.budget.context, finish.usage);
208
+ // A refused or filtered step isn't kept: there's nothing in it to send back.
209
+ if (finish.reason === 'refusal' || finish.reason === 'content-filter') {
210
+ return yield* end('incomplete', {
211
+ error: finish.reason === 'refusal' ? new RefusalError() : new ContentFilterError(),
212
+ errorPart: { code: 'content_filtered', retryable: false },
213
+ });
214
+ }
215
+ for (const part of finish.parts) {
216
+ const wire = add(part);
217
+ if (wire)
218
+ yield wire;
219
+ }
220
+ if (finish.reason === 'error') {
221
+ return yield* end('incomplete', {
222
+ error: new Error(`The ${provider.name} step stopped with an error.`),
223
+ errorPart: { code: 'provider_error', retryable: true },
224
+ });
225
+ }
226
+ if (finish.reason === 'length') {
227
+ console.warn('[chatcops] The reply was cut off at the token limit. Raise `maxTokens` if this keeps happening.');
228
+ return yield* end('incomplete', { reason: 'length' });
229
+ }
230
+ if (finish.reason !== 'tool-calls' || calls.length === 0) {
231
+ return yield* end('complete');
232
+ }
233
+ const callParts = new Map(parts.filter((part) => part.type === 'tool-call').map((part) => [part.toolCallId, part]));
234
+ if (stepNumber >= maxSteps) {
235
+ for (const { call } of calls) {
236
+ const wire = add(resultPart(call, { success: false, message: 'Not run: the reply reached its tool round limit.' }));
237
+ if (wire)
238
+ yield wire;
239
+ }
240
+ return yield* end('incomplete', {
241
+ error: new MaxStepsError(maxSteps - 1),
242
+ errorPart: { code: 'tool_error', retryable: false },
243
+ });
244
+ }
245
+ // Every call of the step runs at once; results are kept in call order.
246
+ const results = await Promise.all(calls.map(({ call, inputError }) => inputError
247
+ ? Promise.resolve({ success: false, message: inputError })
248
+ : tools.run(call, { conversationId: options.conversationId, signal: toolSignal, timeoutMs: options.toolTimeoutMs })));
249
+ for (const [i, { call }] of calls.entries()) {
250
+ const result = results[i];
251
+ const callPart = callParts.get(call.id);
252
+ if (callPart)
253
+ callPart.state = result.success ? 'done' : 'error';
254
+ for (const part of [resultPart(call, result), ...(result.success ? tools.emits(call, result) : [])]) {
255
+ const wire = add(part);
256
+ if (wire)
257
+ yield wire;
258
+ }
259
+ }
260
+ if (signal?.aborted)
261
+ return yield* end('aborted');
262
+ await persist(false);
263
+ }
264
+ /**
265
+ * A provider written for 0.4 has `chat()` and runs tools itself. Its tool
266
+ * calls are recorded through the executor it's given, and their parts are
267
+ * streamed before the next text, the way the 0.5 server sent them.
268
+ */
269
+ async function* legacyTurn() {
270
+ // A 0.4 provider reports no usage, so its replies can only be checked, not charged.
271
+ const budget = yield* checkBudget(1);
272
+ if (budget.ended)
273
+ return budget.ended;
274
+ const queued = [];
275
+ let textId = null;
276
+ let text = null;
277
+ const toolExecutor = async (call) => {
278
+ text = null;
279
+ const callPart = {
280
+ type: 'tool-call', toolCallId: call.id, toolName: call.name, input: call.input, executor: 'server', state: 'pending',
281
+ };
282
+ const callWire = add(callPart);
283
+ if (callWire)
284
+ queued.push(callWire);
285
+ const result = await tools.run(call, { conversationId: options.conversationId, signal: toolSignal, timeoutMs: options.toolTimeoutMs });
286
+ callPart.state = result.success ? 'done' : 'error';
287
+ for (const part of [resultPart(call, result), ...(result.success ? tools.emits(call, result) : [])]) {
288
+ const wire = add(part);
289
+ if (wire)
290
+ queued.push(wire);
291
+ }
292
+ return result;
293
+ };
294
+ try {
295
+ for await (const chunk of provider.chat({
296
+ // Providers written for 0.4 read `content` only, so a reply the
297
+ // visitor walked away from would look finished. Leave it out.
298
+ messages: options.messages.filter((m) => m.status !== 'aborted'),
299
+ systemPrompt: joinSystem(options.systemPrompt, options.systemContext),
300
+ ...(tools.definitions.length ? { tools: tools.definitions } : {}),
301
+ toolExecutor,
302
+ toolTimeoutMs: options.toolTimeoutMs,
303
+ maxTokens: budget.maxTokens,
304
+ temperature: options.temperature,
305
+ signal,
306
+ })) {
307
+ if (signal?.aborted)
308
+ break;
309
+ if (!chunk)
310
+ continue;
311
+ if (queued.length) {
312
+ if (textId) {
313
+ yield { type: 'text-end', id: textId };
314
+ textId = null;
315
+ }
316
+ yield* queued.splice(0);
317
+ }
318
+ if (!textId) {
319
+ textId = `${message.id}-${++textCount}`;
320
+ yield { type: 'text-start', id: textId };
321
+ }
322
+ if (!text) {
323
+ text = { type: 'text', text: '' };
324
+ parts.push(text);
325
+ }
326
+ text.text += chunk;
327
+ yield { type: 'text-delta', id: textId, delta: chunk };
328
+ }
329
+ }
330
+ catch (error) {
331
+ if (textId)
332
+ yield { type: 'text-end', id: textId };
333
+ // Tool parts recorded so far are saved but not streamed, as in 0.5.
334
+ return yield* failed(error);
335
+ }
336
+ if (textId)
337
+ yield { type: 'text-end', id: textId };
338
+ if (signal?.aborted)
339
+ return yield* end('aborted');
340
+ yield* queued.splice(0);
341
+ return yield* end('complete');
342
+ }
343
+ }
344
+ //# sourceMappingURL=run-turn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-turn.js","sourceRoot":"","sources":["../../src/agent/run-turn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAA4D,MAAM,mBAAmB,CAAC;AAY/G,OAAO,EAAE,mBAAmB,EAAwC,MAAM,qBAAqB,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAqB,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErF,sFAAsF;AACtF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AA+CnC,MAAM,QAAQ,GAAiB,gBAAgB,CAAC,EAAE,CAAC,CAAC;AAEpD,2DAA2D;AAC3D,MAAM,UAAU,UAAU,CAAC,YAAoB,EAAE,aAAsB;IACrE,OAAO,aAAa,CAAC,CAAC,CAAC,GAAG,YAAY,OAAO,aAAa,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC;AAC9E,CAAC;AAID,iFAAiF;AACjF,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,SAAS,QAAQ,CAAC,KAAiB,EAAE,IAAgB;IACnD,KAAK,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC;IACtC,KAAK,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC;IACxC,IAAI,IAAI,CAAC,eAAe;QAAE,KAAK,CAA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ition, ToolResult } from '../types.js';
3
+ export interface ToolRunContext {
4
+ conversationId: string;
5
+ signal: AbortSignal;
6
+ timeoutMs?: number;
7
+ }
8
+ /** The tools a turn can call, and how to run them. */
9
+ export interface ToolRegistry {
10
+ /** What the model is told about. */
11
+ definitions: ToolDefinition[];
12
+ /** Runs a call. Never throws: failures come back as `{ success: false }`. */
13
+ run(call: ProviderToolCall, context: ToolRunContext): Promise<ToolResult>;
14
+ /** Parts to add after a call, like a captured lead. */
15
+ emits(call: ProviderToolCall, result: ToolResult): MessagePart[];
16
+ }
17
+ /** A registry over `ChatTool` objects, as the server configures them. */
18
+ export declare function toolRegistry(tools?: ChatTool[]): ToolRegistry;
19
+ /**
20
+ * A registry over tool definitions and one executor function, the 0.4
21
+ * `toolExecutor` shape. The executor gets the call and nothing else.
22
+ */
23
+ export declare function executorRegistry(definitions?: ToolDefinition[], executor?: ProviderToolExecutor): ToolRegistry;
24
+ /** Tool output is stored with the conversation, so it's kept to JSON and a size. */
25
+ export declare const MAX_TOOL_OUTPUT_CHARS = 64000;
26
+ /** The stored output of a call: what the model saw, as plain JSON. */
27
+ export declare function toolOutput(result: ToolResult): unknown;
28
+ //# sourceMappingURL=tool-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-registry.d.ts","sourceRoot":"","sources":["../../src/agent/tool-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,UAAU,EACX,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,cAAc;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,sDAAsD;AACtD,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,WAAW,EAAE,cAAc,EAAE,CAAC;IAC9B,6EAA6E;IAC7E,GAAG,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC1E,uDAAuD;IACvD,KAAK,CAAC,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,UAAU,GAAG,WAAW,EAAE,CAAC;CAClE;AAYD,yEAAyE;AACzE,wBAAgB,YAAY,CAAC,KAAK,GAAE,QAAQ,EAAO,GAAG,YAAY,CAiBjE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,GAAE,cAAc,EAAO,EAAE,QAAQ,CAAC,EAAE,oBAAoB,GAAG,YAAY,CAWlH;AAED,oFAAoF;AACpF,eAAO,MAAM,qBAAqB,QAAS,CAAC;AAE5C,sEAAsE;AACtE,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CActD"}