@pikku/core 0.12.0 → 0.12.2
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 +40 -0
- package/dist/errors/errors.d.ts +6 -0
- package/dist/errors/errors.js +10 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/function/function-runner.d.ts +3 -3
- package/dist/function/function-runner.js +66 -44
- package/dist/function/functions.types.d.ts +1 -0
- package/dist/handle-error.d.ts +2 -2
- package/dist/handle-error.js +2 -2
- package/dist/index.d.ts +5 -3
- package/dist/index.js +2 -1
- package/dist/internal.d.ts +3 -0
- package/dist/internal.js +2 -0
- package/dist/middleware/auth-bearer.d.ts +1 -1
- package/dist/middleware/auth-bearer.js +1 -1
- package/dist/middleware/auth-cookie.d.ts +2 -2
- package/dist/middleware/auth-cookie.js +1 -1
- package/dist/middleware/cors.d.ts +2 -2
- package/dist/middleware/cors.js +45 -37
- package/dist/middleware-runner.d.ts +1 -1
- package/dist/middleware-runner.js +1 -0
- package/dist/permissions.d.ts +2 -2
- package/dist/permissions.js +1 -0
- package/dist/pikku-state.d.ts +9 -8
- package/dist/pikku-state.js +34 -17
- package/dist/schema.d.ts +4 -4
- package/dist/schema.js +9 -5
- package/dist/services/ai-agent-runner-service.d.ts +22 -3
- package/dist/services/ai-run-state-service.d.ts +1 -1
- package/dist/services/ai-storage-service.d.ts +1 -1
- package/dist/services/content-service.d.ts +6 -0
- package/dist/services/gateway-service.d.ts +19 -0
- package/dist/services/gopass-secrets.d.ts +1 -1
- package/dist/services/gopass-secrets.js +3 -0
- package/dist/services/in-memory-ai-run-state-service.d.ts +15 -0
- package/dist/services/in-memory-ai-run-state-service.js +44 -0
- package/dist/services/in-memory-trigger-service.d.ts +0 -1
- package/dist/services/in-memory-trigger-service.js +6 -8
- package/dist/services/index.d.ts +5 -2
- package/dist/services/index.js +2 -0
- package/dist/services/local-content.d.ts +2 -1
- package/dist/services/local-content.js +6 -1
- package/dist/services/local-gateway-service.d.ts +22 -0
- package/dist/services/local-gateway-service.js +51 -0
- package/dist/services/local-secrets.d.ts +2 -2
- package/dist/services/local-variables.d.ts +1 -1
- package/dist/services/logger-console.d.ts +2 -1
- package/dist/services/scheduler-service.d.ts +0 -12
- package/dist/services/scheduler-service.js +0 -6
- package/dist/services/scoped-secret-service.d.ts +1 -1
- package/dist/services/trigger-service.d.ts +0 -7
- package/dist/services/user-session-service.d.ts +3 -3
- package/dist/services/workflow-service.d.ts +2 -3
- package/dist/types/core.types.d.ts +27 -19
- package/dist/types/state.types.d.ts +22 -15
- package/dist/utils.d.ts +5 -5
- package/dist/utils.js +12 -9
- package/dist/wirings/ai-agent/ai-agent-assistant-ui.d.ts +5 -0
- package/dist/wirings/ai-agent/ai-agent-assistant-ui.js +168 -0
- package/dist/wirings/ai-agent/ai-agent-helpers.d.ts +28 -0
- package/dist/wirings/ai-agent/ai-agent-helpers.js +40 -0
- package/dist/wirings/ai-agent/ai-agent-memory.js +13 -2
- package/dist/wirings/ai-agent/ai-agent-prepare.d.ts +4 -5
- package/dist/wirings/ai-agent/ai-agent-prepare.js +80 -31
- package/dist/wirings/ai-agent/ai-agent-registry.d.ts +1 -1
- package/dist/wirings/ai-agent/ai-agent-runner.js +107 -8
- package/dist/wirings/ai-agent/ai-agent-stream.d.ts +2 -1
- package/dist/wirings/ai-agent/ai-agent-stream.js +263 -89
- package/dist/wirings/ai-agent/ai-agent.types.d.ts +96 -4
- package/dist/wirings/ai-agent/index.d.ts +3 -1
- package/dist/wirings/ai-agent/index.js +2 -0
- package/dist/wirings/channel/channel-common.d.ts +2 -2
- package/dist/wirings/channel/channel-handler.d.ts +7 -4
- package/dist/wirings/channel/channel-handler.js +15 -5
- package/dist/wirings/channel/channel-middleware-runner.js +1 -0
- package/dist/wirings/channel/channel-runner.d.ts +5 -5
- package/dist/wirings/channel/channel-runner.js +3 -2
- package/dist/wirings/channel/channel-store.d.ts +1 -1
- package/dist/wirings/channel/channel.types.d.ts +10 -6
- package/dist/wirings/channel/index.d.ts +1 -1
- package/dist/wirings/channel/local/local-channel-handler.d.ts +7 -0
- package/dist/wirings/channel/local/local-channel-handler.js +17 -0
- package/dist/wirings/channel/local/local-channel-runner.d.ts +7 -2
- package/dist/wirings/channel/local/local-channel-runner.js +18 -4
- package/dist/wirings/channel/local/local-eventhub-service.d.ts +2 -2
- package/dist/wirings/channel/log-channels.d.ts +1 -1
- package/dist/wirings/channel/pikku-abstract-channel-handler.d.ts +2 -1
- package/dist/wirings/channel/pikku-abstract-channel-handler.js +1 -0
- package/dist/wirings/channel/serverless/serverless-channel-runner.d.ts +4 -4
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +26 -20
- package/dist/wirings/cli/channel/cli-channel-runner.d.ts +1 -1
- package/dist/wirings/cli/cli-runner.d.ts +2 -2
- package/dist/wirings/cli/cli-runner.js +3 -0
- package/dist/wirings/cli/cli.types.d.ts +3 -3
- package/dist/wirings/cli/command-parser.d.ts +1 -1
- package/dist/wirings/gateway/gateway-runner.d.ts +24 -0
- package/dist/wirings/gateway/gateway-runner.js +325 -0
- package/dist/wirings/gateway/gateway.types.d.ts +127 -0
- package/dist/wirings/gateway/index.d.ts +2 -0
- package/dist/wirings/gateway/index.js +1 -0
- package/dist/wirings/http/http-runner.d.ts +9 -9
- package/dist/wirings/http/http-runner.js +36 -14
- package/dist/wirings/http/http.types.d.ts +2 -6
- package/dist/wirings/http/log-http-routes.d.ts +1 -1
- package/dist/wirings/http/pikku-fetch-http-request.d.ts +1 -1
- package/dist/wirings/http/pikku-fetch-http-response.d.ts +2 -2
- package/dist/wirings/http/pikku-fetch-http-response.js +6 -1
- package/dist/wirings/http/routers/http-router.d.ts +1 -1
- package/dist/wirings/http/routers/path-to-regex.d.ts +2 -2
- package/dist/wirings/mcp/mcp-endpoint-registry.d.ts +1 -1
- package/dist/wirings/mcp/mcp-runner.d.ts +0 -3
- package/dist/wirings/mcp/mcp-runner.js +4 -2
- package/dist/wirings/mcp/mcp.types.d.ts +2 -2
- package/dist/wirings/oauth2/oauth2-client.d.ts +3 -3
- package/dist/wirings/oauth2/wire-oauth2-credential.d.ts +1 -1
- package/dist/wirings/queue/index.d.ts +1 -1
- package/dist/wirings/queue/index.js +1 -1
- package/dist/wirings/queue/queue-runner.d.ts +1 -12
- package/dist/wirings/queue/queue-runner.js +4 -12
- package/dist/wirings/queue/queue.types.d.ts +3 -9
- package/dist/wirings/queue/register-queue-helper.d.ts +2 -2
- package/dist/wirings/queue/register-queue-helper.js +1 -1
- package/dist/wirings/queue/validate-worker-config.d.ts +1 -1
- package/dist/wirings/rpc/index.d.ts +2 -0
- package/dist/wirings/rpc/index.js +1 -0
- package/dist/wirings/rpc/rpc-runner.d.ts +36 -14
- package/dist/wirings/rpc/rpc-runner.js +56 -28
- package/dist/wirings/rpc/rpc-types.d.ts +14 -2
- package/dist/wirings/rpc/wire-addon.d.ts +10 -0
- package/dist/wirings/rpc/wire-addon.js +9 -0
- package/dist/wirings/scheduler/index.d.ts +1 -1
- package/dist/wirings/scheduler/index.js +1 -1
- package/dist/wirings/scheduler/log-schedulers.d.ts +1 -1
- package/dist/wirings/scheduler/scheduler-runner.d.ts +3 -10
- package/dist/wirings/scheduler/scheduler-runner.js +4 -25
- package/dist/wirings/scheduler/scheduler.types.d.ts +2 -2
- package/dist/wirings/trigger/pikku-trigger-service.d.ts +2 -6
- package/dist/wirings/trigger/pikku-trigger-service.js +11 -16
- package/dist/wirings/trigger/trigger-runner.d.ts +1 -5
- package/dist/wirings/trigger/trigger-runner.js +4 -3
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +2 -6
- package/dist/wirings/workflow/pikku-workflow-service.js +20 -29
- package/dist/wirings/workflow/workflow.types.d.ts +2 -2
- package/package.json +4 -2
- package/src/crypto-utils.test.ts +116 -0
- package/src/errors/error.test.ts +143 -2
- package/src/errors/errors.ts +10 -0
- package/src/errors/index.ts +1 -0
- package/src/function/function-runner.test.ts +2 -2
- package/src/function/function-runner.ts +72 -49
- package/src/function/functions.types.ts +1 -0
- package/src/handle-error.test.ts +361 -0
- package/src/handle-error.ts +4 -4
- package/src/index.ts +3 -10
- package/src/internal.ts +6 -0
- package/src/middleware/auth-apikey.test.ts +1 -1
- package/src/middleware/auth-bearer.test.ts +1 -1
- package/src/middleware/auth-bearer.ts +2 -5
- package/src/middleware/auth-cookie.test.ts +1 -1
- package/src/middleware/auth-cookie.ts +3 -5
- package/src/middleware/cors.test.ts +424 -0
- package/src/middleware/cors.ts +14 -6
- package/src/middleware/remote-auth.test.ts +488 -0
- package/src/middleware-runner.test.ts +1 -1
- package/src/middleware-runner.ts +2 -1
- package/src/permissions.test.ts +2 -2
- package/src/permissions.ts +3 -2
- package/src/pikku-state.test.ts +224 -0
- package/src/pikku-state.ts +45 -28
- package/src/schema.test.ts +198 -6
- package/src/schema.ts +11 -7
- package/src/services/ai-agent-runner-service.ts +15 -3
- package/src/services/ai-run-state-service.ts +1 -1
- package/src/services/ai-storage-service.ts +1 -1
- package/src/services/content-service.ts +7 -0
- package/src/services/gateway-service.ts +20 -0
- package/src/services/gopass-secrets.ts +4 -1
- package/src/services/in-memory-ai-run-state-service.ts +73 -0
- package/src/services/in-memory-trigger-service.ts +6 -10
- package/src/services/in-memory-workflow-service.test.ts +351 -0
- package/src/services/index.ts +4 -1
- package/src/services/local-content.ts +9 -3
- package/src/services/local-gateway-service.ts +62 -0
- package/src/services/local-secrets.test.ts +80 -0
- package/src/services/local-secrets.ts +2 -2
- package/src/services/local-variables.test.ts +61 -0
- package/src/services/local-variables.ts +1 -1
- package/src/services/logger-console.test.ts +118 -0
- package/src/services/logger-console.ts +2 -1
- package/src/services/scheduler-service.ts +0 -18
- package/src/services/scoped-secret-service.test.ts +74 -0
- package/src/services/scoped-secret-service.ts +1 -1
- package/src/services/trigger-service.ts +0 -21
- package/src/services/typed-secret-service.test.ts +93 -0
- package/src/services/typed-variables-service.test.ts +73 -0
- package/src/services/user-session-service.test.ts +113 -0
- package/src/services/user-session-service.ts +3 -3
- package/src/services/workflow-service.ts +2 -12
- package/src/time-utils.test.ts +1 -1
- package/src/types/core.types.ts +28 -19
- package/src/types/state.types.ts +32 -15
- package/src/utils.test.ts +350 -0
- package/src/utils.ts +14 -13
- package/src/wirings/ai-agent/ai-agent-assistant-ui.test.ts +363 -0
- package/src/wirings/ai-agent/ai-agent-assistant-ui.ts +238 -0
- package/src/wirings/ai-agent/ai-agent-helpers.test.ts +152 -0
- package/src/wirings/ai-agent/ai-agent-helpers.ts +76 -0
- package/src/wirings/ai-agent/ai-agent-memory.ts +10 -1
- package/src/wirings/ai-agent/ai-agent-model-config.test.ts +115 -0
- package/src/wirings/ai-agent/ai-agent-prepare.ts +98 -46
- package/src/wirings/ai-agent/ai-agent-registry.ts +1 -1
- package/src/wirings/ai-agent/ai-agent-runner.test.ts +245 -3
- package/src/wirings/ai-agent/ai-agent-runner.ts +121 -7
- package/src/wirings/ai-agent/ai-agent-stream.test.ts +430 -24
- package/src/wirings/ai-agent/ai-agent-stream.ts +390 -104
- package/src/wirings/ai-agent/ai-agent.types.ts +91 -4
- package/src/wirings/ai-agent/index.ts +13 -0
- package/src/wirings/channel/channel-common.ts +2 -2
- package/src/wirings/channel/channel-handler.ts +43 -11
- package/src/wirings/channel/channel-middleware-runner.ts +1 -0
- package/src/wirings/channel/channel-runner.ts +6 -6
- package/src/wirings/channel/channel-store.ts +1 -1
- package/src/wirings/channel/channel.types.ts +15 -8
- package/src/wirings/channel/index.ts +1 -0
- package/src/wirings/channel/local/local-channel-handler.ts +26 -0
- package/src/wirings/channel/local/local-channel-runner.test.ts +19 -12
- package/src/wirings/channel/local/local-channel-runner.ts +33 -14
- package/src/wirings/channel/local/local-eventhub-service.test.ts +2 -2
- package/src/wirings/channel/local/local-eventhub-service.ts +2 -2
- package/src/wirings/channel/log-channels.ts +1 -1
- package/src/wirings/channel/pikku-abstract-channel-handler.test.ts +2 -0
- package/src/wirings/channel/pikku-abstract-channel-handler.ts +8 -1
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +38 -33
- package/src/wirings/cli/channel/cli-channel-runner.ts +1 -1
- package/src/wirings/cli/cli-runner.test.ts +1 -1
- package/src/wirings/cli/cli-runner.ts +14 -4
- package/src/wirings/cli/cli.types.ts +3 -3
- package/src/wirings/cli/command-parser.test.ts +1 -1
- package/src/wirings/cli/command-parser.ts +1 -1
- package/src/wirings/gateway/gateway-runner.test.ts +474 -0
- package/src/wirings/gateway/gateway-runner.ts +411 -0
- package/src/wirings/gateway/gateway.types.ts +149 -0
- package/src/wirings/gateway/index.ts +13 -0
- package/src/wirings/http/http-routes.test.ts +1 -1
- package/src/wirings/http/http-runner.test.ts +9 -17
- package/src/wirings/http/http-runner.ts +46 -27
- package/src/wirings/http/http.types.ts +1 -14
- package/src/wirings/http/log-http-routes.ts +1 -1
- package/src/wirings/http/pikku-fetch-http-request.ts +1 -1
- package/src/wirings/http/pikku-fetch-http-response.ts +12 -5
- package/src/wirings/http/routers/http-router.ts +1 -1
- package/src/wirings/http/routers/path-to-regex.test.ts +1 -1
- package/src/wirings/http/routers/path-to-regex.ts +4 -3
- package/src/wirings/mcp/mcp-endpoint-registry.ts +5 -1
- package/src/wirings/mcp/mcp-runner.ts +9 -15
- package/src/wirings/mcp/mcp.types.ts +2 -2
- package/src/wirings/oauth2/oauth2-client.ts +3 -3
- package/src/wirings/oauth2/wire-oauth2-credential.ts +1 -1
- package/src/wirings/queue/index.ts +0 -1
- package/src/wirings/queue/queue-runner.test.ts +52 -25
- package/src/wirings/queue/queue-runner.ts +8 -30
- package/src/wirings/queue/queue.types.ts +3 -13
- package/src/wirings/queue/register-queue-helper.ts +3 -5
- package/src/wirings/queue/validate-worker-config.test.ts +108 -0
- package/src/wirings/queue/validate-worker-config.ts +4 -1
- package/src/wirings/rpc/index.ts +2 -0
- package/src/wirings/rpc/rpc-runner.ts +92 -49
- package/src/wirings/rpc/rpc-types.ts +17 -2
- package/src/wirings/rpc/wire-addon.ts +20 -0
- package/src/wirings/scheduler/index.ts +0 -1
- package/src/wirings/scheduler/log-schedulers.ts +1 -1
- package/src/wirings/scheduler/scheduler-runner.test.ts +49 -60
- package/src/wirings/scheduler/scheduler-runner.ts +9 -56
- package/src/wirings/scheduler/scheduler.types.ts +2 -2
- package/src/wirings/secret/validate-secret-definitions.test.ts +140 -0
- package/src/wirings/trigger/pikku-trigger-service.ts +17 -39
- package/src/wirings/trigger/trigger-runner.test.ts +79 -0
- package/src/wirings/trigger/trigger-runner.ts +8 -11
- package/src/wirings/variable/validate-variable-definitions.test.ts +91 -0
- package/src/wirings/workflow/graph/graph-runner.test.ts +14 -22
- package/src/wirings/workflow/graph/template.test.ts +49 -0
- package/src/wirings/workflow/pikku-workflow-service.test.ts +15 -27
- package/src/wirings/workflow/pikku-workflow-service.ts +29 -45
- package/src/wirings/workflow/workflow-helpers.test.ts +129 -0
- package/src/wirings/workflow/workflow.types.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/src/wirings/workflow/workflow-utils.ts +0 -0
- /package/dist/{wirings/workflow/workflow-utils.d.ts → services/gateway-service.js} +0 -0
- /package/dist/wirings/{workflow/workflow-utils.js → gateway/gateway.types.js} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as assert from 'assert'
|
|
2
2
|
import { test } from 'node:test'
|
|
3
|
-
import { PikkuChannelHandler } from '../channel.types.js'
|
|
4
|
-
import { CoreUserSession } from '../../../types/core.types.js'
|
|
3
|
+
import type { PikkuChannelHandler } from '../channel.types.js'
|
|
4
|
+
import type { CoreUserSession } from '../../../types/core.types.js'
|
|
5
5
|
import { LocalEventHubService } from './local-eventhub-service.js'
|
|
6
6
|
|
|
7
7
|
class MockChannelHandler implements PikkuChannelHandler {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PikkuChannelHandler } from '../channel.types.js'
|
|
2
|
-
import { EventHubService } from '../eventhub-service.js'
|
|
1
|
+
import type { PikkuChannelHandler } from '../channel.types.js'
|
|
2
|
+
import type { EventHubService } from '../eventhub-service.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Implementation of the SubscriptionService interface.
|
|
@@ -10,6 +10,8 @@ class TestChannelHandler extends PikkuAbstractChannelHandler<
|
|
|
10
10
|
public async send(message: { msg: string }, isBinary = false): Promise<void> {
|
|
11
11
|
// Mock send implementation
|
|
12
12
|
}
|
|
13
|
+
|
|
14
|
+
public sendBinary(_data: ArrayBuffer | Uint8Array): void {}
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
let handler: TestChannelHandler
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
BinaryData,
|
|
3
|
+
PikkuChannel,
|
|
4
|
+
PikkuChannelHandler,
|
|
5
|
+
} from './channel.types.js'
|
|
2
6
|
|
|
3
7
|
export abstract class PikkuAbstractChannelHandler<
|
|
4
8
|
OpeningData = unknown,
|
|
@@ -15,12 +19,15 @@ export abstract class PikkuAbstractChannelHandler<
|
|
|
15
19
|
|
|
16
20
|
public abstract send(message: Out, isBinary?: boolean): Promise<void> | void
|
|
17
21
|
|
|
22
|
+
public abstract sendBinary(data: BinaryData): Promise<void> | void
|
|
23
|
+
|
|
18
24
|
public getChannel(): PikkuChannel<OpeningData, Out> {
|
|
19
25
|
if (!this.channel) {
|
|
20
26
|
this.channel = {
|
|
21
27
|
channelId: this.channelId,
|
|
22
28
|
openingData: this.openingData,
|
|
23
29
|
send: this.send.bind(this),
|
|
30
|
+
sendBinary: this.sendBinary.bind(this),
|
|
24
31
|
close: this.close.bind(this),
|
|
25
32
|
state: 'initial',
|
|
26
33
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PikkuWire, WireServices } from '../../../types/core.types.js'
|
|
1
|
+
import type { PikkuWire, WireServices } from '../../../types/core.types.js'
|
|
2
2
|
import { closeWireServices } from '../../../utils.js'
|
|
3
3
|
import { processMessageHandlers } from '../channel-handler.js'
|
|
4
4
|
import { openChannel } from '../channel-runner.js'
|
|
@@ -9,15 +9,19 @@ import type {
|
|
|
9
9
|
PikkuChannelHandlerFactory,
|
|
10
10
|
} from '../channel.types.js'
|
|
11
11
|
import { createHTTPWire } from '../../http/http-runner.js'
|
|
12
|
-
import { ChannelStore } from '../channel-store.js'
|
|
12
|
+
import type { ChannelStore } from '../channel-store.js'
|
|
13
13
|
import { handleHTTPError } from '../../../handle-error.js'
|
|
14
14
|
import {
|
|
15
15
|
PikkuSessionService,
|
|
16
16
|
createMiddlewareSessionWireProps,
|
|
17
17
|
} from '../../../services/user-session-service.js'
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
getSingletonServices,
|
|
20
|
+
getCreateWireServices,
|
|
21
|
+
pikkuState,
|
|
22
|
+
} from '../../../pikku-state.js'
|
|
19
23
|
import { PikkuFetchHTTPRequest } from '../../http/pikku-fetch-http-request.js'
|
|
20
|
-
import { PikkuHTTP } from '../../http/http.types.js'
|
|
24
|
+
import type { PikkuHTTP } from '../../http/http.types.js'
|
|
21
25
|
import { runChannelLifecycleWithMiddleware } from '../channel-common.js'
|
|
22
26
|
|
|
23
27
|
export interface RunServerlessChannelParams<ChannelData>
|
|
@@ -62,13 +66,11 @@ const getVariablesForChannel = ({
|
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
export const runChannelConnect = async ({
|
|
65
|
-
singletonServices,
|
|
66
69
|
channelId,
|
|
67
70
|
channelObject,
|
|
68
71
|
request,
|
|
69
72
|
response,
|
|
70
73
|
route,
|
|
71
|
-
createWireServices,
|
|
72
74
|
channelStore,
|
|
73
75
|
channelHandlerFactory,
|
|
74
76
|
coerceDataFromSchema = true,
|
|
@@ -78,6 +80,8 @@ export const runChannelConnect = async ({
|
|
|
78
80
|
}: Pick<CoreChannel<unknown, any>, 'route'> &
|
|
79
81
|
RunChannelOptions &
|
|
80
82
|
RunServerlessChannelParams<unknown>) => {
|
|
83
|
+
const singletonServices = getSingletonServices()
|
|
84
|
+
const createWireServices = getCreateWireServices()
|
|
81
85
|
let wireServices: WireServices | undefined
|
|
82
86
|
|
|
83
87
|
let http: PikkuHTTP | undefined
|
|
@@ -89,10 +93,8 @@ export const runChannelConnect = async ({
|
|
|
89
93
|
|
|
90
94
|
const { channelConfig, openingData, meta } = await openChannel({
|
|
91
95
|
channelId,
|
|
92
|
-
createWireServices,
|
|
93
96
|
request,
|
|
94
97
|
route,
|
|
95
|
-
singletonServices,
|
|
96
98
|
coerceDataFromSchema,
|
|
97
99
|
userSession,
|
|
98
100
|
})
|
|
@@ -155,9 +157,12 @@ export const runChannelConnect = async ({
|
|
|
155
157
|
}
|
|
156
158
|
|
|
157
159
|
export const runChannelDisconnect = async ({
|
|
158
|
-
|
|
159
|
-
|
|
160
|
+
channelId,
|
|
161
|
+
channelStore,
|
|
162
|
+
channelHandlerFactory,
|
|
160
163
|
}: RunServerlessChannelParams<unknown>): Promise<void> => {
|
|
164
|
+
const singletonServices = getSingletonServices()
|
|
165
|
+
const createWireServices = getCreateWireServices()
|
|
161
166
|
let wireServices: WireServices | undefined
|
|
162
167
|
|
|
163
168
|
// Try to get channel from store. In serverless environments (especially with
|
|
@@ -166,35 +171,31 @@ export const runChannelDisconnect = async ({
|
|
|
166
171
|
// there's nothing to disconnect, so we can return early.
|
|
167
172
|
let channelData
|
|
168
173
|
try {
|
|
169
|
-
channelData = await
|
|
170
|
-
|
|
171
|
-
)
|
|
172
|
-
} catch (error) {
|
|
174
|
+
channelData = await channelStore.getChannelAndSession(channelId)
|
|
175
|
+
} catch {
|
|
173
176
|
singletonServices.logger.info(
|
|
174
|
-
`Channel ${
|
|
177
|
+
`Channel ${channelId} not found during disconnect - already cleaned up`
|
|
175
178
|
)
|
|
176
179
|
return
|
|
177
180
|
}
|
|
178
181
|
|
|
179
182
|
const { openingData, channelName, session } = channelData
|
|
180
183
|
const { channel, channelConfig, meta } = getVariablesForChannel({
|
|
181
|
-
|
|
184
|
+
channelId,
|
|
185
|
+
channelHandlerFactory,
|
|
182
186
|
openingData,
|
|
183
187
|
channelName,
|
|
184
188
|
})
|
|
185
189
|
|
|
186
|
-
const userSession = new PikkuSessionService(
|
|
187
|
-
params.channelStore,
|
|
188
|
-
params.channelId
|
|
189
|
-
)
|
|
190
|
+
const userSession = new PikkuSessionService(channelStore, channelId)
|
|
190
191
|
userSession.setInitial(session)
|
|
191
192
|
const wire: PikkuWire = {
|
|
192
193
|
channel,
|
|
193
194
|
...createMiddlewareSessionWireProps(userSession),
|
|
194
195
|
}
|
|
195
196
|
|
|
196
|
-
if (
|
|
197
|
-
wireServices = await
|
|
197
|
+
if (createWireServices) {
|
|
198
|
+
wireServices = await createWireServices(singletonServices, wire)
|
|
198
199
|
}
|
|
199
200
|
|
|
200
201
|
const services = {
|
|
@@ -219,38 +220,42 @@ export const runChannelDisconnect = async ({
|
|
|
219
220
|
)
|
|
220
221
|
}
|
|
221
222
|
}
|
|
222
|
-
await
|
|
223
|
+
await channelStore.removeChannels([channel.channelId])
|
|
223
224
|
if (wireServices) {
|
|
224
225
|
await closeWireServices(singletonServices.logger, wireServices)
|
|
225
226
|
}
|
|
226
227
|
}
|
|
227
228
|
|
|
228
229
|
export const runChannelMessage = async (
|
|
229
|
-
{
|
|
230
|
+
{
|
|
231
|
+
channelId,
|
|
232
|
+
channelStore,
|
|
233
|
+
channelHandlerFactory,
|
|
234
|
+
}: RunServerlessChannelParams<unknown>,
|
|
230
235
|
data: unknown
|
|
231
236
|
): Promise<unknown> => {
|
|
237
|
+
const singletonServices = getSingletonServices()
|
|
238
|
+
const createWireServices = getCreateWireServices()
|
|
232
239
|
let wireServices: WireServices | undefined
|
|
233
240
|
const { openingData, channelName, session } =
|
|
234
|
-
await
|
|
241
|
+
await channelStore.getChannelAndSession(channelId)
|
|
235
242
|
|
|
236
243
|
const { channel, channelHandler, channelConfig } = getVariablesForChannel({
|
|
237
|
-
|
|
244
|
+
channelId,
|
|
245
|
+
channelHandlerFactory,
|
|
238
246
|
openingData,
|
|
239
247
|
channelName,
|
|
240
248
|
})
|
|
241
249
|
|
|
242
|
-
const userSession = new PikkuSessionService(
|
|
243
|
-
params.channelStore,
|
|
244
|
-
params.channelId
|
|
245
|
-
)
|
|
250
|
+
const userSession = new PikkuSessionService(channelStore, channelId)
|
|
246
251
|
userSession.setInitial(session)
|
|
247
252
|
const wire: PikkuWire = {
|
|
248
253
|
channel,
|
|
249
254
|
...createMiddlewareSessionWireProps(userSession),
|
|
250
255
|
}
|
|
251
256
|
|
|
252
|
-
if (
|
|
253
|
-
wireServices = await
|
|
257
|
+
if (createWireServices) {
|
|
258
|
+
wireServices = await createWireServices(singletonServices, wire)
|
|
254
259
|
}
|
|
255
260
|
|
|
256
261
|
const services = {
|
|
@@ -260,7 +265,7 @@ export const runChannelMessage = async (
|
|
|
260
265
|
|
|
261
266
|
let response: unknown
|
|
262
267
|
try {
|
|
263
|
-
const onMessage = processMessageHandlers(
|
|
268
|
+
const { onMessage } = processMessageHandlers(
|
|
264
269
|
services,
|
|
265
270
|
channelConfig,
|
|
266
271
|
channelHandler,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { pikkuState } from '../../../pikku-state.js'
|
|
2
|
-
import { CorePikkuCLIRender,
|
|
2
|
+
import type { CorePikkuCLIRender, CLIMeta } from '../cli.types.js'
|
|
3
3
|
import { generateCommandHelp, parseCLIArguments } from '../command-parser.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { test, describe, beforeEach, afterEach } from 'node:test'
|
|
2
2
|
import * as assert from 'assert'
|
|
3
3
|
import { NotFoundError } from '../../errors/errors.js'
|
|
4
|
-
import { CorePikkuMiddleware } from '../../types/core.types.js'
|
|
4
|
+
import type { CorePikkuMiddleware } from '../../types/core.types.js'
|
|
5
5
|
import { wireCLI, runCLICommand, pikkuCLIRender } from './cli-runner.js'
|
|
6
6
|
import { pikkuState, resetPikkuState } from '../../pikku-state.js'
|
|
7
7
|
import { addFunction } from '../../function/function-runner.js'
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { NotFoundError, PikkuMissingMetaError } from '../../errors/errors.js'
|
|
2
2
|
import { addFunction, runPikkuFunc } from '../../function/function-runner.js'
|
|
3
3
|
import { pikkuState } from '../../pikku-state.js'
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import type {
|
|
5
|
+
CorePikkuMiddleware,
|
|
6
|
+
CoreUserSession,
|
|
7
|
+
} from '../../types/core.types.js'
|
|
8
|
+
import type {
|
|
6
9
|
CoreCLI,
|
|
7
10
|
CLICommandMeta,
|
|
8
11
|
CLIOption,
|
|
@@ -19,7 +22,7 @@ import type {
|
|
|
19
22
|
CreateConfig,
|
|
20
23
|
CreateSingletonServices,
|
|
21
24
|
} from '../../types/core.types.js'
|
|
22
|
-
import { PikkuChannel } from '../channel/channel.types.js'
|
|
25
|
+
import type { PikkuChannel } from '../channel/channel.types.js'
|
|
23
26
|
import {
|
|
24
27
|
PikkuSessionService,
|
|
25
28
|
createMiddlewareSessionWireProps,
|
|
@@ -318,6 +321,9 @@ export async function runCLICommand({
|
|
|
318
321
|
await Promise.resolve(renderer(singletonServices, data, undefined))
|
|
319
322
|
}
|
|
320
323
|
},
|
|
324
|
+
sendBinary: () => {
|
|
325
|
+
throw new Error('Binary data is not supported on CLI channels')
|
|
326
|
+
},
|
|
321
327
|
close: () => {
|
|
322
328
|
if (channel) {
|
|
323
329
|
channel.state = 'closed'
|
|
@@ -357,7 +363,11 @@ export async function runCLICommand({
|
|
|
357
363
|
// Skip if result is undefined (void functions handle their own output)
|
|
358
364
|
if (renderer && result !== undefined) {
|
|
359
365
|
await Promise.resolve(
|
|
360
|
-
renderer(
|
|
366
|
+
renderer(
|
|
367
|
+
singletonServices,
|
|
368
|
+
result,
|
|
369
|
+
userSession.get() as CoreUserSession | undefined
|
|
370
|
+
)
|
|
361
371
|
)
|
|
362
372
|
}
|
|
363
373
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CorePikkuMiddleware,
|
|
3
3
|
CoreSingletonServices,
|
|
4
4
|
CoreUserSession,
|
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
MiddlewareMetadata,
|
|
7
7
|
PermissionMetadata,
|
|
8
8
|
} from '../../types/core.types.js'
|
|
9
|
-
import {
|
|
9
|
+
import type {
|
|
10
10
|
CorePikkuFunctionConfig,
|
|
11
11
|
CorePikkuPermission,
|
|
12
12
|
CorePikkuFunction,
|
|
13
13
|
CorePikkuFunctionSessionless,
|
|
14
14
|
} from '../../function/functions.types.js'
|
|
15
|
-
import { PikkuChannel } from '../channel/channel.types.js'
|
|
15
|
+
import type { PikkuChannel } from '../channel/channel.types.js'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* CLI option definition
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { test, describe } from 'node:test'
|
|
2
2
|
import * as assert from 'assert'
|
|
3
3
|
import { parseCLIArguments, generateCommandHelp } from './command-parser.js'
|
|
4
|
-
import { CLIMeta } from './cli.types.js'
|
|
4
|
+
import type { CLIMeta } from './cli.types.js'
|
|
5
5
|
|
|
6
6
|
const testMeta: CLIMeta = {
|
|
7
7
|
programs: {
|