@pikku/core 0.12.63 → 0.12.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +147 -0
- package/dist/dev/hot-reload.js +13 -55
- package/dist/dev/module-runner.d.ts +14 -0
- package/dist/dev/module-runner.js +59 -0
- package/dist/dev/reload-meta.d.ts +13 -0
- package/dist/dev/reload-meta.js +22 -0
- package/dist/errors/errors.d.ts +12 -0
- package/dist/errors/errors.js +19 -0
- package/dist/function/function-runner.d.ts +5 -5
- package/dist/function/function-runner.js +39 -111
- package/dist/function/functions.types.d.ts +17 -7
- package/dist/index.d.ts +5 -1
- package/dist/index.js +3 -1
- package/dist/middleware/auth-apikey.d.ts +1 -0
- package/dist/middleware/auth-bearer.d.ts +1 -0
- package/dist/middleware/auth-cookie.d.ts +1 -0
- package/dist/middleware/cors.d.ts +1 -0
- package/dist/middleware/index.d.ts +1 -1
- package/dist/middleware/index.js +1 -1
- package/dist/middleware/remote-auth.d.ts +1 -0
- package/dist/middleware/telemetry.d.ts +2 -0
- package/dist/middleware/timeout.d.ts +1 -0
- package/dist/permissions.d.ts +32 -25
- package/dist/permissions.js +104 -185
- package/dist/pikku-state.js +0 -2
- package/dist/scopes.d.ts +17 -0
- package/dist/scopes.js +59 -0
- package/dist/services/ai-embedding-service.d.ts +31 -0
- package/dist/services/ai-embedding-service.js +1 -0
- package/dist/services/credential-wire-service.d.ts +3 -1
- package/dist/services/credential-wire-service.js +10 -4
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.js +2 -0
- package/dist/services/meta-service.d.ts +15 -2
- package/dist/services/meta-service.js +51 -1
- package/dist/services/queue-webhook-service.d.ts +55 -0
- package/dist/services/queue-webhook-service.js +136 -0
- package/dist/services/scope-service.d.ts +67 -0
- package/dist/services/scope-service.js +1 -0
- package/dist/services/typed-secret-service.d.ts +8 -0
- package/dist/services/typed-secret-service.js +39 -4
- package/dist/services/webhook-service.d.ts +140 -0
- package/dist/services/webhook-service.js +44 -0
- package/dist/services/workflow-service.d.ts +7 -0
- package/dist/types/core.types.d.ts +34 -6
- package/dist/types/state.types.d.ts +20 -2
- package/dist/utils/hmac.d.ts +16 -0
- package/dist/utils/hmac.js +26 -0
- package/dist/utils/safe-fetch.d.ts +51 -0
- package/dist/utils/safe-fetch.js +192 -0
- package/dist/wirings/ai-agent/ai-agent-agui.d.ts +84 -0
- package/dist/wirings/ai-agent/ai-agent-agui.js +305 -0
- package/dist/wirings/ai-agent/ai-agent-prepare.d.ts +41 -1
- package/dist/wirings/ai-agent/ai-agent-prepare.js +146 -6
- package/dist/wirings/ai-agent/ai-agent-runner.js +6 -1
- package/dist/wirings/ai-agent/ai-agent-stream.js +61 -10
- package/dist/wirings/ai-agent/ai-agent.types.d.ts +27 -1
- package/dist/wirings/ai-agent/index.d.ts +1 -0
- package/dist/wirings/ai-agent/index.js +1 -0
- package/dist/wirings/ai-agent/voice-input.d.ts +1 -0
- package/dist/wirings/ai-agent/voice-input.js +2 -38
- package/dist/wirings/ai-agent/voice-output.d.ts +1 -0
- package/dist/wirings/channel/channel-common.js +0 -1
- package/dist/wirings/channel/channel-handler.js +1 -4
- package/dist/wirings/channel/channel-middleware-runner.d.ts +12 -0
- package/dist/wirings/channel/channel-middleware-runner.js +34 -19
- package/dist/wirings/channel/channel.types.d.ts +2 -6
- package/dist/wirings/cli/cli-runner.js +0 -2
- package/dist/wirings/cli/cli.types.d.ts +1 -2
- package/dist/wirings/http/http-routes.js +0 -3
- package/dist/wirings/http/http-runner.d.ts +9 -29
- package/dist/wirings/http/http-runner.js +9 -34
- package/dist/wirings/http/http.types.d.ts +1 -9
- package/dist/wirings/mcp/mcp-runner.js +0 -2
- package/dist/wirings/mcp/mcp.types.d.ts +5 -11
- package/dist/wirings/oauth2/index.d.ts +0 -3
- package/dist/wirings/oauth2/index.js +1 -2
- package/dist/wirings/rpc/addon-runner.d.ts +28 -0
- package/dist/wirings/rpc/addon-runner.js +173 -0
- package/dist/wirings/rpc/index.d.ts +5 -1
- package/dist/wirings/rpc/index.js +3 -1
- package/dist/wirings/rpc/remote-addon-auth.d.ts +26 -0
- package/dist/wirings/rpc/remote-addon-auth.js +43 -0
- package/dist/wirings/rpc/rpc-runner.d.ts +19 -0
- package/dist/wirings/rpc/rpc-runner.js +109 -3
- package/dist/wirings/rpc/rpc-types.d.ts +15 -1
- package/dist/wirings/rpc/wire-addon.js +9 -0
- package/dist/wirings/rpc/wire-remote-addon.d.ts +47 -0
- package/dist/wirings/rpc/wire-remote-addon.js +19 -0
- package/dist/wirings/scope/index.d.ts +3 -0
- package/dist/wirings/scope/index.js +2 -0
- package/dist/wirings/scope/scope.types.d.ts +39 -0
- package/dist/wirings/scope/scope.types.js +1 -0
- package/dist/wirings/scope/validate-scope-definitions.d.ts +16 -0
- package/dist/wirings/scope/validate-scope-definitions.js +76 -0
- package/dist/wirings/scope/wire-scope.d.ts +33 -0
- package/dist/wirings/scope/wire-scope.js +32 -0
- package/dist/wirings/workflow/dsl/index.d.ts +1 -1
- package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +53 -1
- package/dist/wirings/workflow/graph/graph-node.d.ts +2 -0
- package/dist/wirings/workflow/graph/graph-runner.js +3 -0
- package/dist/wirings/workflow/graph/wire-workflow-graph.d.ts +6 -0
- package/dist/wirings/workflow/graph/wire-workflow-graph.js +1 -0
- package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +5 -0
- package/dist/wirings/workflow/index.d.ts +2 -2
- package/dist/wirings/workflow/index.js +1 -1
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +51 -1
- package/dist/wirings/workflow/pikku-workflow-service.js +171 -0
- package/dist/wirings/workflow/workflow.types.d.ts +1 -1
- package/package.json +5 -1
- package/run-tests.sh +1 -0
- package/src/dev/hot-reload.ts +13 -68
- package/src/dev/module-runner.test.ts +169 -0
- package/src/dev/module-runner.ts +103 -0
- package/src/dev/reload-meta.test.ts +31 -2
- package/src/dev/reload-meta.ts +26 -0
- package/src/errors/errors.ts +24 -0
- package/src/function/function-runner.test.ts +276 -142
- package/src/function/function-runner.ts +52 -145
- package/src/function/functions.types.ts +28 -38
- package/src/index.ts +8 -6
- package/src/middleware/index.ts +1 -5
- package/src/permissions.test.ts +153 -372
- package/src/permissions.ts +139 -259
- package/src/pikku-state.ts +0 -2
- package/src/scopes.test.ts +167 -0
- package/src/scopes.ts +69 -0
- package/src/services/ai-embedding-service.ts +31 -0
- package/src/services/credential-wire-service.ts +10 -4
- package/src/services/index.ts +20 -0
- package/src/services/meta-service.ts +68 -3
- package/src/services/queue-webhook-service.test.ts +408 -0
- package/src/services/queue-webhook-service.ts +182 -0
- package/src/services/scope-service.ts +75 -0
- package/src/services/typed-secret-service.test.ts +35 -0
- package/src/services/typed-secret-service.ts +39 -4
- package/src/services/webhook-service.ts +180 -0
- package/src/services/workflow-service.ts +7 -0
- package/src/types/core.types.ts +42 -14
- package/src/types/state.types.ts +23 -3
- package/src/utils/hmac.ts +27 -0
- package/src/utils/safe-fetch.test.ts +373 -0
- package/src/utils/safe-fetch.ts +213 -0
- package/src/wirings/ai-agent/ai-agent-agui.test.ts +1127 -0
- package/src/wirings/ai-agent/ai-agent-agui.ts +386 -0
- package/src/wirings/ai-agent/ai-agent-prepare.test.ts +308 -0
- package/src/wirings/ai-agent/ai-agent-prepare.ts +192 -8
- package/src/wirings/ai-agent/ai-agent-runner.test.ts +48 -1
- package/src/wirings/ai-agent/ai-agent-runner.ts +21 -0
- package/src/wirings/ai-agent/ai-agent-stream.test.ts +198 -10
- package/src/wirings/ai-agent/ai-agent-stream.ts +84 -10
- package/src/wirings/ai-agent/ai-agent.types.ts +28 -0
- package/src/wirings/ai-agent/index.ts +1 -0
- package/src/wirings/ai-agent/voice-input.ts +6 -35
- package/src/wirings/channel/channel-common.ts +0 -1
- package/src/wirings/channel/channel-handler.ts +1 -9
- package/src/wirings/channel/channel-middleware-runner.test.ts +28 -2
- package/src/wirings/channel/channel-middleware-runner.ts +39 -27
- package/src/wirings/channel/channel.types.ts +0 -6
- package/src/wirings/cli/cli-runner.ts +0 -2
- package/src/wirings/cli/cli.types.ts +0 -2
- package/src/wirings/http/http-routes.ts +0 -3
- package/src/wirings/http/http-runner.test.ts +1 -11
- package/src/wirings/http/http-runner.ts +16 -39
- package/src/wirings/http/http.types.ts +1 -10
- package/src/wirings/mcp/mcp-runner.ts +0 -2
- package/src/wirings/mcp/mcp.types.ts +3 -11
- package/src/wirings/oauth2/index.ts +0 -3
- package/src/wirings/rpc/addon-runner.ts +233 -0
- package/src/wirings/rpc/index.ts +17 -1
- package/src/wirings/rpc/remote-addon-auth.ts +69 -0
- package/src/wirings/rpc/rpc-runner.test.ts +319 -16
- package/src/wirings/rpc/rpc-runner.ts +155 -3
- package/src/wirings/rpc/rpc-types.ts +16 -5
- package/src/wirings/rpc/wire-addon.test.ts +6 -3
- package/src/wirings/rpc/wire-addon.ts +9 -0
- package/src/wirings/rpc/wire-remote-addon.ts +57 -0
- package/src/wirings/scope/index.ts +14 -0
- package/src/wirings/scope/scope.test.ts +135 -0
- package/src/wirings/scope/scope.types.ts +44 -0
- package/src/wirings/scope/validate-scope-definitions.ts +110 -0
- package/src/wirings/scope/wire-scope.ts +34 -0
- package/src/wirings/workflow/dsl/index.ts +4 -0
- package/src/wirings/workflow/dsl/workflow-dsl.types.ts +61 -0
- package/src/wirings/workflow/graph/graph-node.ts +2 -0
- package/src/wirings/workflow/graph/graph-runner.test.ts +58 -0
- package/src/wirings/workflow/graph/graph-runner.ts +3 -0
- package/src/wirings/workflow/graph/wire-workflow-graph.ts +7 -0
- package/src/wirings/workflow/graph/workflow-graph.types.ts +5 -0
- package/src/wirings/workflow/index.ts +5 -0
- package/src/wirings/workflow/pikku-workflow-service.test.ts +341 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +236 -0
- package/src/wirings/workflow/workflow-step-session.test.ts +21 -5
- package/src/wirings/workflow/workflow.types.ts +4 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/wirings/oauth2/oauth2-client.test.ts +0 -930
- package/src/wirings/oauth2/oauth2-client.ts +0 -331
- package/src/wirings/oauth2/oauth2-routes.ts +0 -234
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import type { AIStreamChannel, AIStreamEvent } from './ai-agent.types.js'
|
|
2
|
+
import { randomUUID } from './ai-agent-utils.js'
|
|
3
|
+
|
|
4
|
+
type AGUIEvent =
|
|
5
|
+
| { type: 'TEXT_MESSAGE_START'; messageId: string }
|
|
6
|
+
| { type: 'TEXT_MESSAGE_CONTENT'; messageId: string; delta: string }
|
|
7
|
+
| { type: 'TEXT_MESSAGE_END'; messageId: string }
|
|
8
|
+
| { type: 'TOOL_CALL_START'; toolCallId: string; toolCallName: string }
|
|
9
|
+
| { type: 'TOOL_CALL_ARGS'; toolCallId: string; delta: string }
|
|
10
|
+
| { type: 'TOOL_CALL_END'; toolCallId: string; toolCallName: string }
|
|
11
|
+
| {
|
|
12
|
+
type: 'TOOL_CALL_RESULT'
|
|
13
|
+
messageId: string
|
|
14
|
+
toolCallId: string
|
|
15
|
+
role: 'tool'
|
|
16
|
+
content: string
|
|
17
|
+
}
|
|
18
|
+
| { type: 'THINKING_START' }
|
|
19
|
+
| { type: 'THINKING_TEXT_MESSAGE_START'; messageId: string }
|
|
20
|
+
| { type: 'THINKING_TEXT_MESSAGE_CONTENT'; messageId: string; delta: string }
|
|
21
|
+
| { type: 'THINKING_TEXT_MESSAGE_END'; messageId: string }
|
|
22
|
+
| { type: 'THINKING_END' }
|
|
23
|
+
| { type: 'RUN_STARTED'; threadId: string; runId: string }
|
|
24
|
+
| {
|
|
25
|
+
type: 'RUN_FINISHED'
|
|
26
|
+
threadId: string
|
|
27
|
+
runId: string
|
|
28
|
+
model?: string
|
|
29
|
+
usage?: {
|
|
30
|
+
promptTokens: number
|
|
31
|
+
completionTokens: number
|
|
32
|
+
totalTokens: number
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
| { type: 'RUN_ERROR'; message: string; code?: string }
|
|
36
|
+
| { type: 'STEP_STARTED'; stepName: string }
|
|
37
|
+
| { type: 'STEP_FINISHED'; stepName: string }
|
|
38
|
+
| { type: 'CUSTOM'; name: string; value: unknown }
|
|
39
|
+
|
|
40
|
+
export type { AGUIEvent }
|
|
41
|
+
|
|
42
|
+
export type AGUIChannelOptions = {
|
|
43
|
+
threadId?: string
|
|
44
|
+
runId?: string
|
|
45
|
+
/**
|
|
46
|
+
* Late-bound runId source, resolved when the run is opened (first event).
|
|
47
|
+
* Lets the stream path report the AIRunStateService runId on RUN_STARTED
|
|
48
|
+
* even though that id is only created after the channel is wrapped.
|
|
49
|
+
*/
|
|
50
|
+
getRunId?: () => string | undefined
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function resultToString(result: unknown): string {
|
|
54
|
+
if (typeof result === 'string') return result
|
|
55
|
+
try {
|
|
56
|
+
return JSON.stringify(result, (_key, val) =>
|
|
57
|
+
typeof val === 'bigint' ? val.toString() : val
|
|
58
|
+
)
|
|
59
|
+
} catch {
|
|
60
|
+
return String(result)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function wrapChannelWithAGUI(
|
|
65
|
+
inner: AIStreamChannel,
|
|
66
|
+
options?: AGUIChannelOptions
|
|
67
|
+
): AIStreamChannel {
|
|
68
|
+
const threadId = options?.threadId ?? randomUUID()
|
|
69
|
+
let runId: string | null = options?.runId ?? null
|
|
70
|
+
|
|
71
|
+
function resolveRunId(): string {
|
|
72
|
+
if (!runId) {
|
|
73
|
+
runId = options?.getRunId?.() ?? randomUUID()
|
|
74
|
+
}
|
|
75
|
+
return runId
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let textMessageId: string | null = null
|
|
79
|
+
let thinkingMessageId: string | null = null
|
|
80
|
+
let openStepName: string | null = null
|
|
81
|
+
let stepSeq = 0
|
|
82
|
+
let runStartedSent = false
|
|
83
|
+
let terminal = false
|
|
84
|
+
let sawUsage = false
|
|
85
|
+
let usageModel: string | undefined
|
|
86
|
+
const usageTotals = { input: 0, output: 0 }
|
|
87
|
+
|
|
88
|
+
// The AG-UI client rejects any event arriving before RUN_STARTED, so the
|
|
89
|
+
// run is opened lazily with the first translated event.
|
|
90
|
+
function send(event: AGUIEvent): void {
|
|
91
|
+
if (!runStartedSent) {
|
|
92
|
+
runStartedSent = true
|
|
93
|
+
inner.send({
|
|
94
|
+
type: 'RUN_STARTED',
|
|
95
|
+
threadId,
|
|
96
|
+
runId: resolveRunId(),
|
|
97
|
+
} as unknown as AIStreamEvent)
|
|
98
|
+
}
|
|
99
|
+
inner.send(event as unknown as AIStreamEvent)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function endTextMessage(): void {
|
|
103
|
+
if (textMessageId) {
|
|
104
|
+
send({ type: 'TEXT_MESSAGE_END', messageId: textMessageId })
|
|
105
|
+
textMessageId = null
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function endThinkingMessage(): void {
|
|
110
|
+
if (thinkingMessageId) {
|
|
111
|
+
send({ type: 'THINKING_TEXT_MESSAGE_END', messageId: thinkingMessageId })
|
|
112
|
+
send({ type: 'THINKING_END' })
|
|
113
|
+
thinkingMessageId = null
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function endStep(): void {
|
|
118
|
+
if (openStepName) {
|
|
119
|
+
send({ type: 'STEP_FINISHED', stepName: openStepName })
|
|
120
|
+
openStepName = null
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function ensureTextMessage(): string {
|
|
125
|
+
if (!textMessageId) {
|
|
126
|
+
textMessageId = randomUUID()
|
|
127
|
+
send({ type: 'TEXT_MESSAGE_START', messageId: textMessageId })
|
|
128
|
+
}
|
|
129
|
+
return textMessageId
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function ensureThinkingMessage(): string {
|
|
133
|
+
if (!thinkingMessageId) {
|
|
134
|
+
thinkingMessageId = randomUUID()
|
|
135
|
+
send({ type: 'THINKING_START' })
|
|
136
|
+
send({
|
|
137
|
+
type: 'THINKING_TEXT_MESSAGE_START',
|
|
138
|
+
messageId: thinkingMessageId,
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
return thinkingMessageId
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// The AG-UI client treats RUN_FINISHED as terminal and rejects everything
|
|
145
|
+
// after it, so it is emitted exactly once — on 'done' — with the usage
|
|
146
|
+
// accumulated across all steps (per-step 'usage' events must NOT finish
|
|
147
|
+
// the run: on multi-step tool runs later steps would arrive after
|
|
148
|
+
// RUN_FINISHED and the client would drop the whole stream).
|
|
149
|
+
function finishRun(): void {
|
|
150
|
+
endTextMessage()
|
|
151
|
+
endThinkingMessage()
|
|
152
|
+
endStep()
|
|
153
|
+
send({
|
|
154
|
+
type: 'RUN_FINISHED',
|
|
155
|
+
threadId,
|
|
156
|
+
runId: resolveRunId(),
|
|
157
|
+
...(usageModel ? { model: usageModel } : {}),
|
|
158
|
+
...(sawUsage
|
|
159
|
+
? {
|
|
160
|
+
usage: {
|
|
161
|
+
promptTokens: usageTotals.input,
|
|
162
|
+
completionTokens: usageTotals.output,
|
|
163
|
+
totalTokens: usageTotals.input + usageTotals.output,
|
|
164
|
+
},
|
|
165
|
+
}
|
|
166
|
+
: {}),
|
|
167
|
+
})
|
|
168
|
+
terminal = true
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
channelId: inner.channelId,
|
|
173
|
+
openingData: inner.openingData,
|
|
174
|
+
get state() {
|
|
175
|
+
return inner.state
|
|
176
|
+
},
|
|
177
|
+
setState: (s) => inner.setState(s),
|
|
178
|
+
getState: () => inner.getState(),
|
|
179
|
+
clearState: () => inner.clearState(),
|
|
180
|
+
sendBinary: (data) => inner.sendBinary(data),
|
|
181
|
+
close: () => inner.close(),
|
|
182
|
+
|
|
183
|
+
send: (event: AIStreamEvent) => {
|
|
184
|
+
if (terminal) return
|
|
185
|
+
|
|
186
|
+
switch (event.type) {
|
|
187
|
+
case 'text-delta': {
|
|
188
|
+
endThinkingMessage()
|
|
189
|
+
const id = ensureTextMessage()
|
|
190
|
+
send({
|
|
191
|
+
type: 'TEXT_MESSAGE_CONTENT',
|
|
192
|
+
messageId: id,
|
|
193
|
+
delta: event.text,
|
|
194
|
+
})
|
|
195
|
+
break
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
case 'reasoning-delta': {
|
|
199
|
+
endTextMessage()
|
|
200
|
+
const id = ensureThinkingMessage()
|
|
201
|
+
send({
|
|
202
|
+
type: 'THINKING_TEXT_MESSAGE_CONTENT',
|
|
203
|
+
messageId: id,
|
|
204
|
+
delta: event.text,
|
|
205
|
+
})
|
|
206
|
+
break
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
case 'tool-call': {
|
|
210
|
+
endTextMessage()
|
|
211
|
+
endThinkingMessage()
|
|
212
|
+
send({
|
|
213
|
+
type: 'TOOL_CALL_START',
|
|
214
|
+
toolCallId: event.toolCallId,
|
|
215
|
+
toolCallName: event.toolName,
|
|
216
|
+
})
|
|
217
|
+
send({
|
|
218
|
+
type: 'TOOL_CALL_ARGS',
|
|
219
|
+
toolCallId: event.toolCallId,
|
|
220
|
+
delta: resultToString(event.args) || '{}',
|
|
221
|
+
})
|
|
222
|
+
send({
|
|
223
|
+
type: 'TOOL_CALL_END',
|
|
224
|
+
toolCallId: event.toolCallId,
|
|
225
|
+
toolCallName: event.toolName,
|
|
226
|
+
})
|
|
227
|
+
break
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
case 'tool-result': {
|
|
231
|
+
send({
|
|
232
|
+
type: 'TOOL_CALL_RESULT',
|
|
233
|
+
messageId: randomUUID(),
|
|
234
|
+
toolCallId: event.toolCallId,
|
|
235
|
+
role: 'tool',
|
|
236
|
+
content: resultToString(event.result),
|
|
237
|
+
})
|
|
238
|
+
break
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
case 'usage': {
|
|
242
|
+
endTextMessage()
|
|
243
|
+
endThinkingMessage()
|
|
244
|
+
sawUsage = true
|
|
245
|
+
usageTotals.input += event.tokens.input
|
|
246
|
+
usageTotals.output += event.tokens.output
|
|
247
|
+
if (event.model) usageModel = event.model
|
|
248
|
+
break
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
case 'error': {
|
|
252
|
+
endTextMessage()
|
|
253
|
+
endThinkingMessage()
|
|
254
|
+
endStep()
|
|
255
|
+
send({ type: 'RUN_ERROR', message: event.message })
|
|
256
|
+
terminal = true
|
|
257
|
+
break
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
case 'done': {
|
|
261
|
+
finishRun()
|
|
262
|
+
break
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Step names must be unique among active steps on the client and
|
|
266
|
+
// sub-agents reuse step numbers on the shared channel, so each
|
|
267
|
+
// step-start closes the previous step and gets a sequential name.
|
|
268
|
+
case 'step-start': {
|
|
269
|
+
endTextMessage()
|
|
270
|
+
endThinkingMessage()
|
|
271
|
+
endStep()
|
|
272
|
+
stepSeq += 1
|
|
273
|
+
openStepName = `${event.agent ?? 'step'}#${stepSeq}`
|
|
274
|
+
send({ type: 'STEP_STARTED', stepName: openStepName })
|
|
275
|
+
break
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
case 'approval-request': {
|
|
279
|
+
endTextMessage()
|
|
280
|
+
endThinkingMessage()
|
|
281
|
+
send({
|
|
282
|
+
type: 'CUSTOM',
|
|
283
|
+
name: 'pikku:approval-request',
|
|
284
|
+
value: {
|
|
285
|
+
toolCallId: event.toolCallId,
|
|
286
|
+
toolName: event.toolName,
|
|
287
|
+
args: event.args,
|
|
288
|
+
reason: event.reason,
|
|
289
|
+
runId: event.runId,
|
|
290
|
+
agent: event.agent,
|
|
291
|
+
session: event.session,
|
|
292
|
+
},
|
|
293
|
+
})
|
|
294
|
+
break
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
case 'credential-request': {
|
|
298
|
+
endTextMessage()
|
|
299
|
+
endThinkingMessage()
|
|
300
|
+
send({
|
|
301
|
+
type: 'CUSTOM',
|
|
302
|
+
name: 'pikku:credential-request',
|
|
303
|
+
value: {
|
|
304
|
+
toolCallId: event.toolCallId,
|
|
305
|
+
toolName: event.toolName,
|
|
306
|
+
args: event.args,
|
|
307
|
+
credentialName: event.credentialName,
|
|
308
|
+
credentialType: event.credentialType,
|
|
309
|
+
connectUrl: event.connectUrl,
|
|
310
|
+
runId: event.runId,
|
|
311
|
+
agent: event.agent,
|
|
312
|
+
session: event.session,
|
|
313
|
+
},
|
|
314
|
+
})
|
|
315
|
+
break
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
case 'generative-ui': {
|
|
319
|
+
send({
|
|
320
|
+
type: 'CUSTOM',
|
|
321
|
+
name: 'pikku:generative-ui',
|
|
322
|
+
value: { spec: event.spec },
|
|
323
|
+
})
|
|
324
|
+
break
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
case 'data': {
|
|
328
|
+
send({
|
|
329
|
+
type: 'CUSTOM',
|
|
330
|
+
name: 'pikku:data',
|
|
331
|
+
value: { name: event.name, data: event.data },
|
|
332
|
+
})
|
|
333
|
+
break
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
case 'workflow-created': {
|
|
337
|
+
send({
|
|
338
|
+
type: 'CUSTOM',
|
|
339
|
+
name: 'pikku:workflow-created',
|
|
340
|
+
value: { workflowName: event.workflowName, graph: event.graph },
|
|
341
|
+
})
|
|
342
|
+
break
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
case 'agent-call': {
|
|
346
|
+
send({
|
|
347
|
+
type: 'CUSTOM',
|
|
348
|
+
name: 'pikku:agent-call',
|
|
349
|
+
value: {
|
|
350
|
+
agentName: event.agentName,
|
|
351
|
+
session: event.session,
|
|
352
|
+
input: event.input,
|
|
353
|
+
},
|
|
354
|
+
})
|
|
355
|
+
break
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
case 'agent-result': {
|
|
359
|
+
send({
|
|
360
|
+
type: 'CUSTOM',
|
|
361
|
+
name: 'pikku:agent-result',
|
|
362
|
+
value: {
|
|
363
|
+
agentName: event.agentName,
|
|
364
|
+
session: event.session,
|
|
365
|
+
result: event.result,
|
|
366
|
+
},
|
|
367
|
+
})
|
|
368
|
+
break
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
case 'suspended': {
|
|
372
|
+
send({
|
|
373
|
+
type: 'CUSTOM',
|
|
374
|
+
name: 'pikku:suspended',
|
|
375
|
+
value: { reason: event.reason, missingRpcs: event.missingRpcs },
|
|
376
|
+
})
|
|
377
|
+
break
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
case 'audio-delta':
|
|
381
|
+
case 'audio-done':
|
|
382
|
+
break
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
}
|
|
386
|
+
}
|