@tinyweb_dev/agent-framework-agent 0.1.0 → 0.3.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 (144) hide show
  1. package/dist/agent.d.ts +116 -0
  2. package/dist/agent.d.ts.map +1 -0
  3. package/dist/attachments.d.ts +41 -0
  4. package/dist/attachments.d.ts.map +1 -0
  5. package/dist/bus/bus.d.ts +46 -0
  6. package/dist/bus/bus.d.ts.map +1 -0
  7. package/dist/bus/index.d.ts +2 -0
  8. package/dist/bus/index.d.ts.map +1 -0
  9. package/dist/define-tool.d.ts +13 -0
  10. package/dist/define-tool.d.ts.map +1 -0
  11. package/dist/events.d.ts +136 -0
  12. package/dist/events.d.ts.map +1 -0
  13. package/dist/http-handlers.cjs +253 -0
  14. package/dist/http-handlers.cjs.map +1 -0
  15. package/dist/http-handlers.d.ts +49 -0
  16. package/dist/http-handlers.d.ts.map +1 -0
  17. package/dist/http-handlers.js +251 -0
  18. package/dist/http-handlers.js.map +1 -0
  19. package/dist/index.cjs +2073 -0
  20. package/dist/index.cjs.map +1 -0
  21. package/dist/index.d.ts +19 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +2015 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/loop-guard.d.ts +42 -0
  26. package/dist/loop-guard.d.ts.map +1 -0
  27. package/dist/mcp/client.d.ts +25 -0
  28. package/dist/mcp/client.d.ts.map +1 -0
  29. package/dist/mcp/index.cjs +66 -0
  30. package/dist/mcp/index.cjs.map +1 -0
  31. package/{src/mcp/index.ts → dist/mcp/index.d.ts} +2 -1
  32. package/dist/mcp/index.d.ts.map +1 -0
  33. package/dist/mcp/index.js +63 -0
  34. package/dist/mcp/index.js.map +1 -0
  35. package/dist/permission.d.ts +26 -0
  36. package/dist/permission.d.ts.map +1 -0
  37. package/dist/plugin/apply.d.ts +12 -0
  38. package/dist/plugin/apply.d.ts.map +1 -0
  39. package/dist/plugin/index.cjs +63 -0
  40. package/dist/plugin/index.cjs.map +1 -0
  41. package/dist/plugin/index.d.ts +4 -0
  42. package/dist/plugin/index.d.ts.map +1 -0
  43. package/dist/plugin/index.js +52 -0
  44. package/dist/plugin/index.js.map +1 -0
  45. package/dist/plugin/loader.d.ts +3 -0
  46. package/dist/plugin/loader.d.ts.map +1 -0
  47. package/dist/plugin/types.d.ts +98 -0
  48. package/dist/plugin/types.d.ts.map +1 -0
  49. package/dist/prompt/index.d.ts +51 -0
  50. package/dist/prompt/index.d.ts.map +1 -0
  51. package/dist/prompt/objective.d.ts +29 -0
  52. package/dist/prompt/objective.d.ts.map +1 -0
  53. package/dist/prompt/response-style.d.ts +19 -0
  54. package/dist/prompt/response-style.d.ts.map +1 -0
  55. package/dist/prompt/tool-use-guidelines.d.ts +22 -0
  56. package/dist/prompt/tool-use-guidelines.d.ts.map +1 -0
  57. package/dist/prompt/tool-use.d.ts +12 -0
  58. package/dist/prompt/tool-use.d.ts.map +1 -0
  59. package/dist/runtime.d.ts +7 -0
  60. package/dist/runtime.d.ts.map +1 -0
  61. package/dist/session/adapter.d.ts +40 -0
  62. package/dist/session/adapter.d.ts.map +1 -0
  63. package/dist/session/compaction.d.ts +37 -0
  64. package/dist/session/compaction.d.ts.map +1 -0
  65. package/dist/session/index.d.ts +7 -0
  66. package/dist/session/index.d.ts.map +1 -0
  67. package/dist/session/memory.cjs +130 -0
  68. package/dist/session/memory.cjs.map +1 -0
  69. package/dist/session/memory.d.ts +3 -0
  70. package/dist/session/memory.d.ts.map +1 -0
  71. package/dist/session/memory.js +128 -0
  72. package/dist/session/memory.js.map +1 -0
  73. package/dist/session/overflow.d.ts +19 -0
  74. package/dist/session/overflow.d.ts.map +1 -0
  75. package/dist/session/postgres.cjs +245 -0
  76. package/dist/session/postgres.cjs.map +1 -0
  77. package/dist/session/postgres.d.ts +10 -0
  78. package/dist/session/postgres.d.ts.map +1 -0
  79. package/dist/session/postgres.js +243 -0
  80. package/dist/session/postgres.js.map +1 -0
  81. package/dist/session/processor.d.ts +52 -0
  82. package/dist/session/processor.d.ts.map +1 -0
  83. package/dist/session/replay.d.ts +4 -0
  84. package/dist/session/replay.d.ts.map +1 -0
  85. package/dist/session/schema.d.ts +104 -0
  86. package/dist/session/schema.d.ts.map +1 -0
  87. package/dist/session/sqlite.cjs +236 -0
  88. package/dist/session/sqlite.cjs.map +1 -0
  89. package/dist/session/sqlite.d.ts +3 -0
  90. package/dist/session/sqlite.d.ts.map +1 -0
  91. package/dist/session/sqlite.js +234 -0
  92. package/dist/session/sqlite.js.map +1 -0
  93. package/dist/session-api.cjs +56 -0
  94. package/dist/session-api.cjs.map +1 -0
  95. package/dist/session-api.d.ts +36 -0
  96. package/dist/session-api.d.ts.map +1 -0
  97. package/dist/session-api.js +54 -0
  98. package/dist/session-api.js.map +1 -0
  99. package/dist/skill/index.cjs +81 -0
  100. package/dist/skill/index.cjs.map +1 -0
  101. package/dist/skill/index.d.ts +10 -0
  102. package/dist/skill/index.d.ts.map +1 -0
  103. package/dist/skill/index.js +78 -0
  104. package/dist/skill/index.js.map +1 -0
  105. package/dist/sse-handler.d.ts +27 -0
  106. package/dist/sse-handler.d.ts.map +1 -0
  107. package/dist/transcript.d.ts +81 -0
  108. package/dist/transcript.d.ts.map +1 -0
  109. package/package.json +54 -19
  110. package/src/agent.ts +0 -317
  111. package/src/attachments.ts +0 -155
  112. package/src/bus/bus.ts +0 -89
  113. package/src/bus/index.ts +0 -1
  114. package/src/define-tool.ts +0 -41
  115. package/src/events.ts +0 -162
  116. package/src/http-handlers.ts +0 -251
  117. package/src/index.ts +0 -120
  118. package/src/loop-guard.ts +0 -99
  119. package/src/mcp/client.ts +0 -110
  120. package/src/permission.ts +0 -72
  121. package/src/plugin/apply.ts +0 -89
  122. package/src/plugin/index.ts +0 -3
  123. package/src/plugin/loader.ts +0 -42
  124. package/src/plugin/types.ts +0 -134
  125. package/src/prompt/index.ts +0 -90
  126. package/src/prompt/objective.ts +0 -104
  127. package/src/prompt/response-style.ts +0 -59
  128. package/src/prompt/tool-use-guidelines.ts +0 -57
  129. package/src/prompt/tool-use.ts +0 -27
  130. package/src/runtime.ts +0 -22
  131. package/src/session/adapter.ts +0 -37
  132. package/src/session/compaction.ts +0 -160
  133. package/src/session/index.ts +0 -11
  134. package/src/session/memory.ts +0 -154
  135. package/src/session/overflow.ts +0 -50
  136. package/src/session/postgres.ts +0 -330
  137. package/src/session/processor.ts +0 -500
  138. package/src/session/replay.ts +0 -140
  139. package/src/session/schema.ts +0 -140
  140. package/src/session/sqlite.ts +0 -281
  141. package/src/session-api.ts +0 -103
  142. package/src/skill/index.ts +0 -113
  143. package/src/sse-handler.ts +0 -67
  144. package/src/transcript.ts +0 -126
@@ -1,155 +0,0 @@
1
- /**
2
- * Public attachment shape forwarded from HTTP/UI → agent.run.
3
- * MVP: image-only, base64 inline OR pre-uploaded URL.
4
- * Validation enforced both client-side (chat-ui) and server-side (http-handlers).
5
- */
6
- export type AttachmentInput = {
7
- readonly type: "image"
8
- readonly mediaType: string
9
- /** Either `data` (raw base64, no `data:` prefix) OR `url` (http/https/file/data:). Exactly one. */
10
- readonly data?: string
11
- readonly url?: string
12
- readonly filename?: string
13
- }
14
-
15
- export type AttachmentErrorCode =
16
- | "attachment_too_large"
17
- | "attachment_unsupported_type"
18
- | "attachment_invalid"
19
- | "attachment_too_many"
20
-
21
- export type ValidateAttachmentsConfig = {
22
- readonly imageMimes?: ReadonlySet<string>
23
- readonly maxBytesPerFile?: number
24
- readonly maxBytesTotal?: number
25
- readonly maxCount?: number
26
- }
27
-
28
- export type ValidateOk = { readonly ok: true; readonly value: ReadonlyArray<AttachmentInput> }
29
- export type ValidateErr = {
30
- readonly ok: false
31
- readonly code: AttachmentErrorCode
32
- readonly message: string
33
- }
34
- export type ValidateResult = ValidateOk | ValidateErr
35
-
36
- export const DEFAULT_IMAGE_MIMES: ReadonlySet<string> = new Set(["image/png", "image/jpeg", "image/webp", "image/gif"])
37
- export const DEFAULT_MAX_BYTES_PER_FILE = 8 * 1024 * 1024
38
- export const DEFAULT_MAX_BYTES_TOTAL = 16 * 1024 * 1024
39
- export const DEFAULT_MAX_COUNT = 4
40
-
41
- const base64ByteLength = (b64: string): number => {
42
- // Strip optional data URL prefix `data:<mime>;base64,`.
43
- const idx = b64.indexOf("base64,")
44
- const body = idx >= 0 ? b64.slice(idx + "base64,".length) : b64
45
- const padding = body.endsWith("==") ? 2 : body.endsWith("=") ? 1 : 0
46
- return Math.max(0, Math.floor((body.length * 3) / 4) - padding)
47
- }
48
-
49
- const isHttpOrFile = (s: string) =>
50
- s.startsWith("http://") || s.startsWith("https://") || s.startsWith("file://") || s.startsWith("data:")
51
-
52
- /**
53
- * Validate raw attachments. Pure function — no I/O. First failure short-circuits.
54
- *
55
- * Order: count → per-item (mime, exactly-one-of, size) → total size.
56
- */
57
- export const validateAttachments = (
58
- raw: unknown,
59
- config?: ValidateAttachmentsConfig,
60
- ): ValidateResult => {
61
- if (raw === undefined || raw === null) return { ok: true, value: [] }
62
- if (!Array.isArray(raw))
63
- return { ok: false, code: "attachment_invalid", message: "attachments must be an array" }
64
-
65
- const imageMimes = config?.imageMimes ?? DEFAULT_IMAGE_MIMES
66
- const maxBytesPerFile = config?.maxBytesPerFile ?? DEFAULT_MAX_BYTES_PER_FILE
67
- const maxBytesTotal = config?.maxBytesTotal ?? DEFAULT_MAX_BYTES_TOTAL
68
- const maxCount = config?.maxCount ?? DEFAULT_MAX_COUNT
69
-
70
- if (raw.length > maxCount)
71
- return {
72
- ok: false,
73
- code: "attachment_too_many",
74
- message: `Too many attachments (max ${maxCount}, received ${raw.length})`,
75
- }
76
-
77
- const out: AttachmentInput[] = []
78
- let totalBytes = 0
79
-
80
- for (let i = 0; i < raw.length; i++) {
81
- const item = raw[i]
82
- if (!item || typeof item !== "object")
83
- return { ok: false, code: "attachment_invalid", message: `attachments[${i}] must be an object` }
84
-
85
- const obj = item as Record<string, unknown>
86
- if (obj.type !== "image")
87
- return {
88
- ok: false,
89
- code: "attachment_unsupported_type",
90
- message: `attachments[${i}].type must be "image" (received ${String(obj.type)})`,
91
- }
92
-
93
- const mediaType = obj.mediaType
94
- if (typeof mediaType !== "string" || mediaType.length === 0)
95
- return { ok: false, code: "attachment_invalid", message: `attachments[${i}].mediaType is required` }
96
- if (!imageMimes.has(mediaType))
97
- return {
98
- ok: false,
99
- code: "attachment_unsupported_type",
100
- message: `Unsupported attachment type: ${mediaType}`,
101
- }
102
-
103
- const data = typeof obj.data === "string" ? obj.data : undefined
104
- const url = typeof obj.url === "string" ? obj.url : undefined
105
-
106
- if (!data && !url)
107
- return {
108
- ok: false,
109
- code: "attachment_invalid",
110
- message: `attachments[${i}] requires either "data" (base64) or "url"`,
111
- }
112
- if (data && url)
113
- return {
114
- ok: false,
115
- code: "attachment_invalid",
116
- message: `attachments[${i}] must not set both "data" and "url"`,
117
- }
118
-
119
- if (url && !isHttpOrFile(url))
120
- return {
121
- ok: false,
122
- code: "attachment_invalid",
123
- message: `attachments[${i}].url must be http(s)/file/data scheme`,
124
- }
125
-
126
- if (data) {
127
- const bytes = base64ByteLength(data)
128
- if (bytes === 0)
129
- return { ok: false, code: "attachment_invalid", message: `attachments[${i}].data is empty or malformed` }
130
- if (bytes > maxBytesPerFile)
131
- return {
132
- ok: false,
133
- code: "attachment_too_large",
134
- message: `Attachment ${obj.filename ?? `#${i}`} exceeds ${maxBytesPerFile} bytes (got ${bytes})`,
135
- }
136
- totalBytes += bytes
137
- if (totalBytes > maxBytesTotal)
138
- return {
139
- ok: false,
140
- code: "attachment_too_large",
141
- message: `Total attachment bytes exceed ${maxBytesTotal} (got ${totalBytes})`,
142
- }
143
- }
144
-
145
- out.push({
146
- type: "image",
147
- mediaType,
148
- data,
149
- url,
150
- filename: typeof obj.filename === "string" ? obj.filename : undefined,
151
- })
152
- }
153
-
154
- return { ok: true, value: out }
155
- }
package/src/bus/bus.ts DELETED
@@ -1,89 +0,0 @@
1
- import { Effect, PubSub, Stream } from "effect"
2
- import type { Message, SessionID } from "../session/schema"
3
- import type { AgentEvent } from "../events"
4
-
5
- // Bus event union — type-tagged for filtering
6
- export type SessionStartedEvent = {
7
- readonly type: "session-started"
8
- readonly sessionId: SessionID | string
9
- readonly agentName: string
10
- }
11
-
12
- export type SessionMessageEvent = {
13
- readonly type: "session-message"
14
- readonly sessionId: SessionID | string
15
- readonly message: Message
16
- }
17
-
18
- export type SessionIdleEvent = {
19
- readonly type: "session-idle"
20
- readonly sessionId: SessionID | string
21
- }
22
-
23
- export type ToolExecutingEvent = {
24
- readonly type: "tool-executing"
25
- readonly sessionId: SessionID | string
26
- readonly callID: string
27
- readonly name: string
28
- readonly input: unknown
29
- }
30
-
31
- export type ToolCompletedEvent = {
32
- readonly type: "tool-completed"
33
- readonly sessionId: SessionID | string
34
- readonly callID: string
35
- readonly name: string
36
- readonly output: unknown
37
- }
38
-
39
- export type AgentEventBusEvent = {
40
- readonly type: "agent-event"
41
- readonly sessionId: SessionID | string
42
- readonly event: AgentEvent
43
- }
44
-
45
- export type BusEvent =
46
- | SessionStartedEvent
47
- | SessionMessageEvent
48
- | SessionIdleEvent
49
- | ToolExecutingEvent
50
- | ToolCompletedEvent
51
- | AgentEventBusEvent
52
-
53
- export type Bus = {
54
- readonly publish: (event: BusEvent) => Effect.Effect<void>
55
- readonly subscribe: <K extends BusEvent["type"]>(
56
- type: K,
57
- ) => Stream.Stream<Extract<BusEvent, { type: K }>>
58
- readonly subscribeAll: () => Stream.Stream<BusEvent>
59
- }
60
-
61
- export const makeBus = (): Bus => {
62
- const pubsubEffect = PubSub.unbounded<BusEvent>()
63
- let cached: PubSub.PubSub<BusEvent> | undefined
64
-
65
- const get = (): Effect.Effect<PubSub.PubSub<BusEvent>> => {
66
- if (cached) return Effect.succeed(cached)
67
- return pubsubEffect.pipe(
68
- Effect.tap((p) => {
69
- cached = p
70
- return Effect.void
71
- }),
72
- )
73
- }
74
-
75
- const publish = (event: BusEvent): Effect.Effect<void> =>
76
- Effect.flatMap(get(), (pubsub) => Effect.asVoid(PubSub.publish(pubsub, event)))
77
-
78
- const subscribeAll = (): Stream.Stream<BusEvent> =>
79
- Stream.unwrap(Effect.map(get(), (pubsub) => Stream.fromPubSub(pubsub)))
80
-
81
- const subscribe = <K extends BusEvent["type"]>(
82
- type: K,
83
- ): Stream.Stream<Extract<BusEvent, { type: K }>> =>
84
- subscribeAll().pipe(
85
- Stream.filter((e): e is Extract<BusEvent, { type: K }> => e.type === type),
86
- )
87
-
88
- return { publish, subscribe, subscribeAll }
89
- }
package/src/bus/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./bus"
@@ -1,41 +0,0 @@
1
- import { Tool, ToolFailure, type ToolSchema } from "@tinyweb-agent-framework/llm"
2
- import { Effect, Schema } from "effect"
3
-
4
- export type ToolExecuteAsync<Params, Success> = (input: Params) => Promise<Success>
5
- export type ToolExecuteEffect<Params, Success> = (
6
- input: Params,
7
- ) => Effect.Effect<Success, ToolFailure>
8
-
9
- export type DefineToolConfig<P extends ToolSchema<any>, S extends ToolSchema<any>> = {
10
- readonly name?: string
11
- readonly description: string
12
- readonly parameters: P
13
- readonly success?: S
14
- readonly execute:
15
- | ToolExecuteAsync<Schema.Schema.Type<P>, Schema.Schema.Type<S>>
16
- | ToolExecuteEffect<Schema.Schema.Type<P>, Schema.Schema.Type<S>>
17
- }
18
-
19
- const wrapExecute = <Params, Success>(
20
- execute: ToolExecuteAsync<Params, Success> | ToolExecuteEffect<Params, Success>,
21
- ) =>
22
- (input: Params): Effect.Effect<Success, ToolFailure> => {
23
- const result = execute(input)
24
- if (Effect.isEffect(result)) return result as Effect.Effect<Success, ToolFailure>
25
- return Effect.tryPromise({
26
- try: () => result as Promise<Success>,
27
- catch: (cause) => new ToolFailure({ message: cause instanceof Error ? cause.message : String(cause) }),
28
- })
29
- }
30
-
31
- export function defineTool<P extends ToolSchema<any>, S extends ToolSchema<any> = typeof Schema.Unknown>(
32
- config: DefineToolConfig<P, S>,
33
- ) {
34
- const success = (config.success ?? Schema.Unknown) as S
35
- return Tool.make({
36
- description: config.description,
37
- parameters: config.parameters,
38
- success,
39
- execute: wrapExecute(config.execute),
40
- })
41
- }
package/src/events.ts DELETED
@@ -1,162 +0,0 @@
1
- import type { LLMEvent } from "@tinyweb-agent-framework/llm"
2
-
3
- export type TextDeltaEvent = {
4
- readonly type: "text-delta"
5
- readonly id: string
6
- readonly text: string
7
- }
8
-
9
- export type TextEndEvent = {
10
- readonly type: "text-end"
11
- readonly id: string
12
- }
13
-
14
- export type ReasoningDeltaEvent = {
15
- readonly type: "reasoning-delta"
16
- readonly id: string
17
- readonly text: string
18
- }
19
-
20
- export type ToolCallEvent = {
21
- readonly type: "tool-call"
22
- readonly id: string
23
- readonly name: string
24
- readonly input: unknown
25
- }
26
-
27
- export type ToolResultEvent = {
28
- readonly type: "tool-result"
29
- readonly id: string
30
- readonly name: string
31
- readonly result: unknown
32
- }
33
-
34
- export type ToolErrorEvent = {
35
- readonly type: "tool-error"
36
- readonly id: string
37
- readonly name: string
38
- readonly message: string
39
- }
40
-
41
- export type StepFinishEvent = {
42
- readonly type: "step-finish"
43
- readonly index: number
44
- readonly reason: string
45
- readonly usage?: unknown
46
- }
47
-
48
- export type FinishEvent = {
49
- readonly type: "finish"
50
- readonly reason: string
51
- readonly usage?: unknown
52
- }
53
-
54
- export type ErrorEvent = {
55
- readonly type: "error"
56
- readonly message: string
57
- readonly retryable?: boolean
58
- /**
59
- * Optional structured code for client-side branching (e.g.
60
- * `"attachment_too_large"`, `"attachment_unsupported_type"`).
61
- * Free-form string — consumers should treat unknown codes as generic errors.
62
- */
63
- readonly code?: string
64
- }
65
-
66
- /**
67
- * Source of an auto-compaction (context-condense) pass.
68
- *
69
- * - `preflight` — the agent estimated the upcoming prompt would exceed the
70
- * usable budget and ran `compact()` BEFORE the provider call. Cheaper and
71
- * more controllable.
72
- * - `overflow-retry` — the provider returned `ContextOverflowReason`; the
73
- * agent ran `compact()` and retried the same turn once. Surfaced so UIs
74
- * can show "context overflow — recovering…" copy distinct from a regular
75
- * pre-flight condense.
76
- * - `manual` — RESERVED. Not emitted yet (no manual trigger exists), but
77
- * reserved on the discriminated union so adding a "Condense Now" button
78
- * later doesn't break consumers' exhaustive switches.
79
- */
80
- export type CondenseTrigger = "preflight" | "overflow-retry" | "manual"
81
-
82
- /**
83
- * Emitted IMMEDIATELY before `compact()` runs. UI consumers should render a
84
- * spinner/pill — compaction can take 2–5s on a long thread because it makes
85
- * its own LLM call.
86
- */
87
- export type ContextCondenseStartEvent = {
88
- readonly type: "context-condense-start"
89
- readonly trigger: CondenseTrigger
90
- /** Estimated prompt tokens the agent would have sent without compacting. */
91
- readonly estimatedTokens?: number
92
- /** The usable budget (`limits.context − reserved`) that the estimate exceeded. */
93
- readonly budgetTokens?: number
94
- }
95
-
96
- /**
97
- * Emitted after a SUCCESSFUL compaction. Carries the summariser's output plus
98
- * before/after token counts and (when the route exposes it) the call cost.
99
- * This is the persistent, replay-friendly record of what happened.
100
- */
101
- export type ContextCondenseEvent = {
102
- readonly type: "context-condense"
103
- readonly trigger: CondenseTrigger
104
- /** Compaction summary text — already truncated if the summariser overflowed. */
105
- readonly summary: string
106
- /** ID of the persisted compaction marker user message — cross-references `sessions.messages(...)`. */
107
- readonly markerId: string
108
- /** Approximate input tokens BEFORE compaction (estimateTokens of the head slice). */
109
- readonly prevTokens?: number
110
- /** Approximate input tokens AFTER compaction (estimateTokens of `[marker, ...tail]`). */
111
- readonly newTokens?: number
112
- /** USD cost of the summariser LLM call when the route surfaces it. */
113
- readonly cost?: number
114
- /** Model id used for the summariser (today: same as the main agent model). */
115
- readonly modelId?: string
116
- }
117
-
118
- /**
119
- * Emitted when `compact()` itself errored or, on the `overflow-retry` path,
120
- * when the post-compaction retry still overflowed (`retryExhausted: true`).
121
- *
122
- * Distinct from the generic `error` event so UIs can render it inline next
123
- * to the condense spinner without tearing down the assistant turn.
124
- */
125
- export type ContextCondenseErrorEvent = {
126
- readonly type: "context-condense-error"
127
- readonly trigger: CondenseTrigger
128
- readonly message: string
129
- /** True ONLY on the second consecutive overflow — replaces the old "compaction retry exhausted" message. */
130
- readonly retryExhausted?: boolean
131
- }
132
-
133
- export type AgentEvent =
134
- | TextDeltaEvent
135
- | TextEndEvent
136
- | ReasoningDeltaEvent
137
- | ToolCallEvent
138
- | ToolResultEvent
139
- | ToolErrorEvent
140
- | StepFinishEvent
141
- | FinishEvent
142
- | ErrorEvent
143
- | ContextCondenseStartEvent
144
- | ContextCondenseEvent
145
- | ContextCondenseErrorEvent
146
-
147
- export const fromLLMEvent = (event: LLMEvent): AgentEvent | undefined => {
148
- if (event.type === "text-delta") return { type: "text-delta", id: event.id, text: event.text }
149
- if (event.type === "text-end") return { type: "text-end", id: event.id }
150
- if (event.type === "reasoning-delta") return { type: "reasoning-delta", id: event.id, text: event.text }
151
- if (event.type === "tool-call") return { type: "tool-call", id: event.id, name: event.name, input: event.input }
152
- if (event.type === "tool-result")
153
- return { type: "tool-result", id: event.id, name: event.name, result: event.result.value }
154
- if (event.type === "tool-error")
155
- return { type: "tool-error", id: event.id, name: event.name, message: event.message }
156
- if (event.type === "step-finish")
157
- return { type: "step-finish", index: event.index, reason: event.reason, usage: event.usage }
158
- if (event.type === "request-finish") return { type: "finish", reason: event.reason, usage: event.usage }
159
- if (event.type === "provider-error")
160
- return { type: "error", message: event.message, retryable: event.retryable }
161
- return undefined
162
- }