@pikku/core 0.12.19 → 0.12.21
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 +77 -0
- package/dist/dev/hot-reload.js +20 -6
- package/dist/errors/error-handler.d.ts +1 -1
- package/dist/errors/error-handler.js +2 -2
- package/dist/function/function-runner.js +53 -3
- package/dist/function/functions.types.d.ts +3 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/middleware/index.d.ts +2 -2
- package/dist/middleware/index.js +2 -2
- package/dist/middleware/telemetry.d.ts +2 -2
- package/dist/middleware/telemetry.js +2 -2
- package/dist/middleware-runner.d.ts +15 -27
- package/dist/middleware-runner.js +25 -30
- package/dist/permissions.d.ts +15 -22
- package/dist/permissions.js +30 -25
- package/dist/pikku-request.js +1 -1
- package/dist/pikku-state.js +2 -3
- package/dist/services/ai-agent-runner-service.d.ts +1 -0
- package/dist/services/content-service.d.ts +66 -37
- package/dist/services/in-memory-queue-service.js +1 -1
- package/dist/services/in-memory-workflow-service.d.ts +15 -13
- package/dist/services/in-memory-workflow-service.js +31 -13
- package/dist/services/index.d.ts +1 -1
- package/dist/services/local-content.d.ts +10 -12
- package/dist/services/local-content.js +54 -38
- package/dist/services/user-session-service.d.ts +1 -1
- package/dist/testing/service-tests.js +24 -0
- package/dist/types/core.types.d.ts +4 -0
- package/dist/types/state.types.d.ts +2 -18
- package/dist/wirings/ai-agent/ai-agent-memory.d.ts +24 -5
- package/dist/wirings/ai-agent/ai-agent-memory.js +128 -23
- package/dist/wirings/ai-agent/ai-agent-model-config.d.ts +10 -1
- package/dist/wirings/ai-agent/ai-agent-model-config.js +15 -35
- package/dist/wirings/ai-agent/ai-agent-prepare.js +4 -1
- package/dist/wirings/ai-agent/ai-agent-runner.js +45 -31
- package/dist/wirings/ai-agent/ai-agent-stream.js +63 -34
- package/dist/wirings/ai-agent/ai-agent.types.d.ts +20 -0
- package/dist/wirings/channel/channel-handler.js +1 -1
- package/dist/wirings/channel/channel-store.d.ts +13 -0
- package/dist/wirings/channel/channel.types.d.ts +3 -0
- package/dist/wirings/channel/local/local-channel-runner.js +23 -5
- package/dist/wirings/channel/pikku-abstract-channel-handler.js +8 -0
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +9 -0
- package/dist/wirings/cli/cli-runner.js +24 -5
- package/dist/wirings/cli/command-parser.js +19 -4
- package/dist/wirings/http/http-runner.js +72 -36
- package/dist/wirings/http/http.types.d.ts +1 -0
- package/dist/wirings/http/pikku-fetch-http-request.js +3 -1
- package/dist/wirings/http/web-request.js +32 -0
- package/dist/wirings/rpc/rpc-runner.d.ts +3 -2
- package/dist/wirings/rpc/rpc-runner.js +45 -11
- package/dist/wirings/workflow/graph/graph-node.d.ts +8 -0
- package/dist/wirings/workflow/graph/graph-node.js +4 -0
- package/dist/wirings/workflow/graph/graph-runner.js +12 -10
- package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +4 -0
- package/dist/wirings/workflow/index.d.ts +1 -1
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +81 -16
- package/dist/wirings/workflow/pikku-workflow-service.js +266 -45
- package/dist/wirings/workflow/workflow.types.d.ts +34 -0
- package/package.json +1 -1
- package/run-tests.sh +4 -1
- package/src/dev/hot-reload.test.ts +62 -11
- package/src/dev/hot-reload.ts +28 -7
- package/src/errors/error-handler.ts +8 -2
- package/src/errors/error.test.ts +2 -0
- package/src/function/function-runner.test.ts +500 -10
- package/src/function/function-runner.ts +68 -3
- package/src/function/functions.types.ts +3 -2
- package/src/index.ts +22 -3
- package/src/middleware/index.ts +11 -2
- package/src/middleware/telemetry.ts +2 -2
- package/src/middleware-runner.test.ts +16 -16
- package/src/middleware-runner.ts +42 -30
- package/src/permissions.test.ts +27 -24
- package/src/permissions.ts +41 -25
- package/src/pikku-request.test.ts +35 -0
- package/src/pikku-request.ts +1 -1
- package/src/pikku-state.ts +2 -3
- package/src/run-tests-script.test.ts +18 -0
- package/src/services/ai-agent-runner-service.ts +1 -0
- package/src/services/content-service.ts +79 -51
- package/src/services/in-memory-queue-service.ts +1 -1
- package/src/services/in-memory-session-store.ts +1 -2
- package/src/services/in-memory-workflow-service.test.ts +33 -11
- package/src/services/in-memory-workflow-service.ts +49 -13
- package/src/services/index.ts +10 -1
- package/src/services/local-content.test.ts +54 -0
- package/src/services/local-content.ts +80 -53
- package/src/services/typed-credential-service.ts +3 -3
- package/src/services/typed-secret-service.ts +3 -3
- package/src/services/typed-variables-service.ts +3 -3
- package/src/services/user-session-service.ts +4 -4
- package/src/testing/service-tests.ts +30 -0
- package/src/types/core.types.ts +6 -2
- package/src/types/state.types.ts +2 -13
- package/src/wirings/ai-agent/ai-agent-memory.test.ts +324 -0
- package/src/wirings/ai-agent/ai-agent-memory.ts +187 -36
- package/src/wirings/ai-agent/ai-agent-model-config.test.ts +12 -90
- package/src/wirings/ai-agent/ai-agent-model-config.ts +14 -38
- package/src/wirings/ai-agent/ai-agent-prepare.test.ts +292 -0
- package/src/wirings/ai-agent/ai-agent-prepare.ts +4 -1
- package/src/wirings/ai-agent/ai-agent-registry.test.ts +230 -3
- package/src/wirings/ai-agent/ai-agent-runner.test.ts +625 -6
- package/src/wirings/ai-agent/ai-agent-runner.ts +65 -50
- package/src/wirings/ai-agent/ai-agent-stream.test.ts +544 -5
- package/src/wirings/ai-agent/ai-agent-stream.ts +71 -69
- package/src/wirings/ai-agent/ai-agent.types.ts +24 -0
- package/src/wirings/channel/channel-handler.test.ts +272 -0
- package/src/wirings/channel/channel-handler.ts +1 -1
- package/src/wirings/channel/channel-middleware-runner.test.ts +163 -0
- package/src/wirings/channel/channel-store.ts +19 -0
- package/src/wirings/channel/channel.types.ts +4 -0
- package/src/wirings/channel/local/local-channel-runner.test.ts +63 -0
- package/src/wirings/channel/local/local-channel-runner.ts +41 -5
- package/src/wirings/channel/local/local-eventhub-service.ts +3 -3
- package/src/wirings/channel/pikku-abstract-channel-handler.ts +9 -2
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +23 -5
- package/src/wirings/cli/channel/cli-raw-channel-runner.ts +7 -2
- package/src/wirings/cli/cli-runner.test.ts +255 -2
- package/src/wirings/cli/cli-runner.ts +31 -10
- package/src/wirings/cli/cli.types.ts +4 -8
- package/src/wirings/cli/command-parser.test.ts +83 -0
- package/src/wirings/cli/command-parser.ts +23 -4
- package/src/wirings/http/http-runner.test.ts +296 -1
- package/src/wirings/http/http-runner.ts +87 -57
- package/src/wirings/http/http.types.ts +11 -26
- package/src/wirings/http/pikku-fetch-http-request.ts +8 -4
- package/src/wirings/http/pikku-fetch-http-response.test.ts +41 -0
- package/src/wirings/http/web-request.test.ts +115 -0
- package/src/wirings/http/web-request.ts +43 -5
- package/src/wirings/mcp/mcp-runner.test.ts +367 -0
- package/src/wirings/queue/queue.types.ts +2 -5
- package/src/wirings/rpc/rpc-runner.test.ts +511 -0
- package/src/wirings/rpc/rpc-runner.ts +60 -21
- package/src/wirings/rpc/wire-addon.test.ts +57 -0
- package/src/wirings/workflow/graph/graph-node.ts +12 -0
- package/src/wirings/workflow/graph/graph-runner.test.ts +98 -0
- package/src/wirings/workflow/graph/graph-runner.ts +28 -10
- package/src/wirings/workflow/graph/workflow-graph.types.ts +4 -0
- package/src/wirings/workflow/index.ts +1 -0
- package/src/wirings/workflow/pikku-workflow-service.test.ts +19 -2
- package/src/wirings/workflow/pikku-workflow-service.ts +370 -71
- package/src/wirings/workflow/workflow-queue-workers.test.ts +131 -0
- package/src/wirings/workflow/workflow.types.ts +68 -5
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
resolveMemoryServices,
|
|
21
21
|
loadContextMessages,
|
|
22
22
|
trimMessages,
|
|
23
|
+
getWorkingMemoryMiddleware,
|
|
23
24
|
} from './ai-agent-memory.js'
|
|
24
25
|
import {
|
|
25
26
|
prepareAgentRun,
|
|
@@ -47,6 +48,21 @@ function stripNulls(obj: unknown): unknown {
|
|
|
47
48
|
}
|
|
48
49
|
import { randomUUID } from 'crypto'
|
|
49
50
|
|
|
51
|
+
function extractStructuredAssistantOutput(object: unknown): {
|
|
52
|
+
text: string | null
|
|
53
|
+
uiSpec: unknown | null
|
|
54
|
+
} {
|
|
55
|
+
if (!object || typeof object !== 'object') {
|
|
56
|
+
return { text: null, uiSpec: null }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const record = object as Record<string, unknown>
|
|
60
|
+
return {
|
|
61
|
+
text: typeof record.text === 'string' ? record.text : null,
|
|
62
|
+
uiSpec: record.ui ?? null,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
50
66
|
export async function runAIAgent(
|
|
51
67
|
agentName: string,
|
|
52
68
|
input: AIAgentInput,
|
|
@@ -65,7 +81,6 @@ export async function runAIAgent(
|
|
|
65
81
|
runnerParams,
|
|
66
82
|
maxSteps,
|
|
67
83
|
missingRpcs,
|
|
68
|
-
workingMemoryJsonSchema,
|
|
69
84
|
workingMemorySchemaName,
|
|
70
85
|
} = await prepareAgentRun(agentName, input, params, sessionMap)
|
|
71
86
|
|
|
@@ -96,7 +111,15 @@ export async function runAIAgent(
|
|
|
96
111
|
}
|
|
97
112
|
}
|
|
98
113
|
|
|
99
|
-
const aiMiddlewares: PikkuAIMiddlewareHooks[] =
|
|
114
|
+
const aiMiddlewares: PikkuAIMiddlewareHooks[] = [
|
|
115
|
+
...getWorkingMemoryMiddleware(memoryConfig, storage, {
|
|
116
|
+
threadId,
|
|
117
|
+
workingMemorySchemaName,
|
|
118
|
+
logger: singletonServices.logger,
|
|
119
|
+
schemaService: singletonServices.schema,
|
|
120
|
+
}),
|
|
121
|
+
...(agent.aiMiddleware ?? []),
|
|
122
|
+
]
|
|
100
123
|
|
|
101
124
|
let modifiedMessages = runnerParams.messages
|
|
102
125
|
let modifiedInstructions = runnerParams.instructions
|
|
@@ -228,13 +251,7 @@ export async function runAIAgent(
|
|
|
228
251
|
input.resourceId,
|
|
229
252
|
memoryConfig,
|
|
230
253
|
userMessage,
|
|
231
|
-
{ text: '', steps: completedStepsForSave }
|
|
232
|
-
{
|
|
233
|
-
workingMemoryJsonSchema,
|
|
234
|
-
workingMemorySchemaName,
|
|
235
|
-
logger: singletonServices.logger,
|
|
236
|
-
schemaService: singletonServices.schema,
|
|
237
|
-
}
|
|
254
|
+
{ text: '', steps: completedStepsForSave }
|
|
238
255
|
)
|
|
239
256
|
|
|
240
257
|
if (storage) {
|
|
@@ -280,30 +297,16 @@ export async function runAIAgent(
|
|
|
280
297
|
appendStepMessages(runnerParams, stepResult)
|
|
281
298
|
}
|
|
282
299
|
|
|
283
|
-
const finalText = lastStepResult?.text ?? ''
|
|
284
300
|
const finalObject = lastStepResult?.object
|
|
301
|
+
const structuredOutput = extractStructuredAssistantOutput(finalObject)
|
|
302
|
+
const finalText = structuredOutput.text ?? lastStepResult?.text ?? ''
|
|
285
303
|
|
|
286
304
|
const result = {
|
|
287
305
|
text: finalText,
|
|
288
306
|
steps: accumulatedSteps,
|
|
289
307
|
}
|
|
290
308
|
|
|
291
|
-
|
|
292
|
-
storage,
|
|
293
|
-
threadId,
|
|
294
|
-
input.resourceId,
|
|
295
|
-
memoryConfig,
|
|
296
|
-
userMessage,
|
|
297
|
-
result,
|
|
298
|
-
{
|
|
299
|
-
workingMemoryJsonSchema,
|
|
300
|
-
workingMemorySchemaName,
|
|
301
|
-
logger: singletonServices.logger,
|
|
302
|
-
schemaService: singletonServices.schema,
|
|
303
|
-
}
|
|
304
|
-
)
|
|
305
|
-
|
|
306
|
-
let outputText = responseText
|
|
309
|
+
let outputText = finalText
|
|
307
310
|
let outputMessages = runnerParams.messages
|
|
308
311
|
for (let i = aiMiddlewares.length - 1; i >= 0; i--) {
|
|
309
312
|
const mw = aiMiddlewares[i]
|
|
@@ -318,6 +321,19 @@ export async function runAIAgent(
|
|
|
318
321
|
}
|
|
319
322
|
}
|
|
320
323
|
|
|
324
|
+
await saveMessages(
|
|
325
|
+
storage,
|
|
326
|
+
threadId,
|
|
327
|
+
input.resourceId,
|
|
328
|
+
memoryConfig,
|
|
329
|
+
userMessage,
|
|
330
|
+
{
|
|
331
|
+
...result,
|
|
332
|
+
text: outputText,
|
|
333
|
+
uiSpec: structuredOutput.uiSpec,
|
|
334
|
+
}
|
|
335
|
+
)
|
|
336
|
+
|
|
321
337
|
await aiRunState.updateRun(runId, {
|
|
322
338
|
status: 'completed',
|
|
323
339
|
usage: { ...totalUsage, model: agent.model },
|
|
@@ -535,7 +551,15 @@ async function continueAfterToolResultSync(
|
|
|
535
551
|
|
|
536
552
|
const instructions = await buildInstructions(resolvedName, packageName)
|
|
537
553
|
|
|
538
|
-
const aiMiddlewares: PikkuAIMiddlewareHooks[] =
|
|
554
|
+
const aiMiddlewares: PikkuAIMiddlewareHooks[] = [
|
|
555
|
+
...getWorkingMemoryMiddleware(memoryConfig, storage, {
|
|
556
|
+
threadId: run.threadId,
|
|
557
|
+
workingMemorySchemaName,
|
|
558
|
+
logger: singletonServices.logger,
|
|
559
|
+
schemaService: singletonServices.schema,
|
|
560
|
+
}),
|
|
561
|
+
...(agent.aiMiddleware ?? []),
|
|
562
|
+
]
|
|
539
563
|
let modifiedMessages = trimmedMessages
|
|
540
564
|
let modifiedInstructions = instructions
|
|
541
565
|
for (const mw of aiMiddlewares) {
|
|
@@ -666,13 +690,7 @@ async function continueAfterToolResultSync(
|
|
|
666
690
|
run.resourceId,
|
|
667
691
|
memoryConfig,
|
|
668
692
|
null,
|
|
669
|
-
{ text: '', steps: completedSteps }
|
|
670
|
-
{
|
|
671
|
-
workingMemoryJsonSchema,
|
|
672
|
-
workingMemorySchemaName,
|
|
673
|
-
logger: singletonServices.logger,
|
|
674
|
-
schemaService: singletonServices.schema,
|
|
675
|
-
}
|
|
693
|
+
{ text: '', steps: completedSteps }
|
|
676
694
|
)
|
|
677
695
|
}
|
|
678
696
|
|
|
@@ -727,22 +745,7 @@ async function continueAfterToolResultSync(
|
|
|
727
745
|
steps: accumulatedSteps,
|
|
728
746
|
}
|
|
729
747
|
|
|
730
|
-
|
|
731
|
-
storage,
|
|
732
|
-
run.threadId,
|
|
733
|
-
run.resourceId,
|
|
734
|
-
memoryConfig,
|
|
735
|
-
null as any,
|
|
736
|
-
result,
|
|
737
|
-
{
|
|
738
|
-
workingMemoryJsonSchema,
|
|
739
|
-
workingMemorySchemaName,
|
|
740
|
-
logger: singletonServices.logger,
|
|
741
|
-
schemaService: singletonServices.schema,
|
|
742
|
-
}
|
|
743
|
-
)
|
|
744
|
-
|
|
745
|
-
let outputText = responseText
|
|
748
|
+
let outputText = finalText
|
|
746
749
|
let outputMessages = runnerParams.messages
|
|
747
750
|
for (let i = aiMiddlewares.length - 1; i >= 0; i--) {
|
|
748
751
|
const mw = aiMiddlewares[i]
|
|
@@ -757,6 +760,18 @@ async function continueAfterToolResultSync(
|
|
|
757
760
|
}
|
|
758
761
|
}
|
|
759
762
|
|
|
763
|
+
await saveMessages(
|
|
764
|
+
storage,
|
|
765
|
+
run.threadId,
|
|
766
|
+
run.resourceId,
|
|
767
|
+
memoryConfig,
|
|
768
|
+
null as any,
|
|
769
|
+
{
|
|
770
|
+
...result,
|
|
771
|
+
text: outputText,
|
|
772
|
+
}
|
|
773
|
+
)
|
|
774
|
+
|
|
760
775
|
await aiRunState.updateRun(run.runId, {
|
|
761
776
|
status: 'completed',
|
|
762
777
|
usage: { ...totalUsage, model: agent.model },
|