@peers-app/peers-sdk 0.14.0 → 0.15.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.
- package/dist/context/data-context.d.ts +4 -4
- package/dist/context/data-context.js +1 -1
- package/dist/context/index.d.ts +3 -3
- package/dist/context/index.js +4 -0
- package/dist/context/user-context-singleton.js +13 -14
- package/dist/context/user-context.d.ts +4 -4
- package/dist/context/user-context.js +48 -31
- package/dist/data/assistants.d.ts +1 -1
- package/dist/data/assistants.js +35 -24
- package/dist/data/change-tracking.d.ts +8 -8
- package/dist/data/change-tracking.js +45 -39
- package/dist/data/channels.js +5 -5
- package/dist/data/data-locks.d.ts +2 -2
- package/dist/data/data-locks.js +21 -23
- package/dist/data/data-locks.test.js +73 -75
- package/dist/data/device-sync-info.d.ts +1 -1
- package/dist/data/device-sync-info.js +4 -4
- package/dist/data/devices.d.ts +1 -1
- package/dist/data/devices.js +9 -12
- package/dist/data/embeddings.js +14 -11
- package/dist/data/files/file-read-stream.d.ts +2 -2
- package/dist/data/files/file-read-stream.js +23 -14
- package/dist/data/files/file-write-stream.d.ts +2 -2
- package/dist/data/files/file-write-stream.js +8 -8
- package/dist/data/files/file.types.d.ts +2 -2
- package/dist/data/files/file.types.js +17 -11
- package/dist/data/files/files.d.ts +6 -6
- package/dist/data/files/files.js +17 -19
- package/dist/data/files/files.test.js +213 -214
- package/dist/data/files/index.d.ts +4 -4
- package/dist/data/files/index.js +4 -4
- package/dist/data/group-member-roles.js +2 -2
- package/dist/data/group-members.d.ts +5 -5
- package/dist/data/group-members.js +27 -18
- package/dist/data/group-members.test.js +73 -73
- package/dist/data/group-permissions.d.ts +3 -3
- package/dist/data/group-permissions.js +13 -11
- package/dist/data/group-share.d.ts +2 -2
- package/dist/data/group-share.js +29 -24
- package/dist/data/groups.d.ts +4 -4
- package/dist/data/groups.js +27 -19
- package/dist/data/groups.test.js +44 -44
- package/dist/data/index.d.ts +6 -6
- package/dist/data/index.js +6 -6
- package/dist/data/knowledge/peer-types.js +9 -9
- package/dist/data/messages.d.ts +5 -5
- package/dist/data/messages.js +43 -30
- package/dist/data/orm/client-proxy.data-source.d.ts +4 -4
- package/dist/data/orm/client-proxy.data-source.js +10 -12
- package/dist/data/orm/cursor.d.ts +1 -1
- package/dist/data/orm/cursor.js +2 -2
- package/dist/data/orm/cursor.test.js +92 -93
- package/dist/data/orm/data-query.d.ts +3 -3
- package/dist/data/orm/data-query.js +24 -18
- package/dist/data/orm/data-query.mongo.d.ts +1 -1
- package/dist/data/orm/data-query.mongo.js +49 -51
- package/dist/data/orm/data-query.mongo.test.js +173 -204
- package/dist/data/orm/data-query.sqlite.d.ts +1 -1
- package/dist/data/orm/data-query.sqlite.js +84 -73
- package/dist/data/orm/data-query.sqlite.test.js +164 -176
- package/dist/data/orm/data-query.test.js +216 -224
- package/dist/data/orm/decorators.js +3 -3
- package/dist/data/orm/dependency-injection.test.js +53 -56
- package/dist/data/orm/doc.d.ts +4 -4
- package/dist/data/orm/doc.js +17 -21
- package/dist/data/orm/event-registry.d.ts +1 -1
- package/dist/data/orm/event-registry.test.js +16 -16
- package/dist/data/orm/factory.d.ts +2 -2
- package/dist/data/orm/factory.js +33 -33
- package/dist/data/orm/index.d.ts +10 -10
- package/dist/data/orm/index.js +10 -10
- package/dist/data/orm/multi-cursors.d.ts +1 -1
- package/dist/data/orm/multi-cursors.js +6 -6
- package/dist/data/orm/multi-cursors.test.js +152 -144
- package/dist/data/orm/sql.data-source.d.ts +7 -7
- package/dist/data/orm/sql.data-source.js +88 -93
- package/dist/data/orm/sql.data-source.test.js +109 -101
- package/dist/data/orm/subscribable.data-source.d.ts +4 -4
- package/dist/data/orm/subscribable.data-source.js +5 -5
- package/dist/data/orm/table-container-events.test.js +34 -26
- package/dist/data/orm/table-container.d.ts +6 -6
- package/dist/data/orm/table-container.js +33 -21
- package/dist/data/orm/table-container.test.js +64 -53
- package/dist/data/orm/table-definitions.system.d.ts +3 -3
- package/dist/data/orm/table-definitions.system.js +3 -3
- package/dist/data/orm/table-definitions.type.d.ts +5 -5
- package/dist/data/orm/table-dependencies.d.ts +2 -2
- package/dist/data/orm/table.d.ts +5 -5
- package/dist/data/orm/table.event-source.test.js +105 -115
- package/dist/data/orm/table.js +35 -34
- package/dist/data/orm/types.d.ts +3 -3
- package/dist/data/orm/types.js +26 -25
- package/dist/data/orm/types.test.js +166 -92
- package/dist/data/package-permissions.d.ts +1 -1
- package/dist/data/package-permissions.js +2 -2
- package/dist/data/package-version-permissions.d.ts +1 -1
- package/dist/data/package-version-permissions.js +2 -2
- package/dist/data/package-versions.d.ts +9 -9
- package/dist/data/package-versions.js +47 -33
- package/dist/data/packages.d.ts +2 -2
- package/dist/data/packages.js +36 -18
- package/dist/data/packages.utils.d.ts +2 -2
- package/dist/data/packages.utils.js +4 -4
- package/dist/data/persistent-vars.d.ts +15 -15
- package/dist/data/persistent-vars.js +165 -154
- package/dist/data/table-definitions-table.d.ts +5 -5
- package/dist/data/table-definitions-table.js +13 -12
- package/dist/data/tool-tests.js +6 -6
- package/dist/data/tools.js +29 -19
- package/dist/data/user-permissions.d.ts +1 -1
- package/dist/data/user-permissions.js +5 -5
- package/dist/data/user-permissions.test.js +90 -88
- package/dist/data/user-trust-levels.js +10 -10
- package/dist/data/users.d.ts +4 -4
- package/dist/data/users.js +16 -15
- package/dist/data/voice-messages.d.ts +2 -2
- package/dist/data/voice-messages.js +13 -13
- package/dist/data/welcome-modal.pvar.js +3 -1
- package/dist/data/workflow-logs.js +26 -18
- package/dist/data/workflow-runs.d.ts +6 -6
- package/dist/data/workflow-runs.js +70 -44
- package/dist/data/workflows.d.ts +2 -2
- package/dist/data/workflows.js +7 -9
- package/dist/device/binary-peer-connection-v2.d.ts +7 -7
- package/dist/device/binary-peer-connection-v2.js +32 -28
- package/dist/device/binary-peer-connection-v2.test.js +80 -67
- package/dist/device/binary-peer-connection.d.ts +7 -7
- package/dist/device/binary-peer-connection.js +29 -28
- package/dist/device/binary-peer-connection.test.js +35 -31
- package/dist/device/connection.d.ts +5 -5
- package/dist/device/connection.js +59 -48
- package/dist/device/connection.test.js +74 -68
- package/dist/device/device-election.d.ts +2 -2
- package/dist/device/device-election.js +25 -20
- package/dist/device/device-election.test.js +35 -36
- package/dist/device/device.d.ts +2 -2
- package/dist/device/device.js +10 -4
- package/dist/device/device.test.js +16 -17
- package/dist/device/get-trust-level-fn.d.ts +2 -2
- package/dist/device/get-trust-level-fn.js +22 -11
- package/dist/device/get-trust-level-fn.test.js +58 -58
- package/dist/device/socket-io-binary-peer.d.ts +1 -1
- package/dist/device/socket-io-binary-peer.js +16 -13
- package/dist/device/socket.type.d.ts +2 -2
- package/dist/device/streamed-socket.d.ts +2 -2
- package/dist/device/streamed-socket.js +8 -8
- package/dist/device/streamed-socket.test.js +40 -40
- package/dist/device/tx-encoding.test.js +77 -77
- package/dist/events.d.ts +1 -1
- package/dist/events.js +5 -2
- package/dist/group-invite/group-invite.js +110 -19
- package/dist/group-invite/group-invite.pvars.d.ts +2 -2
- package/dist/group-invite/group-invite.pvars.js +21 -13
- package/dist/group-invite/group-invite.types.d.ts +1 -1
- package/dist/group-invite/index.d.ts +3 -3
- package/dist/group-invite/index.js +1 -1
- package/dist/index.d.ts +25 -24
- package/dist/index.js +30 -25
- package/dist/keys.d.ts +3 -3
- package/dist/keys.js +31 -30
- package/dist/keys.test.js +69 -61
- package/dist/logging/console-logger.d.ts +1 -1
- package/dist/logging/console-logger.js +35 -40
- package/dist/logging/console-logger.test.js +115 -115
- package/dist/logging/console-logs.table.d.ts +3 -3
- package/dist/logging/console-logs.table.js +28 -23
- package/dist/mentions.js +16 -12
- package/dist/observable.d.ts +2 -2
- package/dist/observable.js +15 -9
- package/dist/observable.test.js +47 -47
- package/dist/package-loader/get-require.js +3 -4
- package/dist/package-loader/package-loader.d.ts +2 -2
- package/dist/package-loader/package-loader.js +52 -34
- package/dist/peers-ui/peers-ui.d.ts +2 -2
- package/dist/peers-ui/peers-ui.js +2 -4
- package/dist/peers-ui/peers-ui.types.d.ts +3 -3
- package/dist/peers-ui/peers-ui.types.js +0 -1
- package/dist/rpc-types.d.ts +61 -59
- package/dist/rpc-types.js +61 -55
- package/dist/serial-json.d.ts +1 -1
- package/dist/serial-json.js +50 -43
- package/dist/serial-json.test.js +22 -22
- package/dist/system-ids.js +8 -8
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/tools-factory.d.ts +1 -1
- package/dist/tools/tools-factory.js +2 -2
- package/dist/types/assistant-runner-args.d.ts +3 -3
- package/dist/types/peer-device.d.ts +1 -1
- package/dist/types/peers-package.d.ts +3 -3
- package/dist/types/workflow-logger.d.ts +1 -1
- package/dist/types/workflow-run-context.d.ts +4 -4
- package/dist/types/workflow.d.ts +4 -4
- package/dist/types/workflow.js +27 -14
- package/dist/types/zod-types.d.ts +2 -1
- package/dist/types/zod-types.js +9 -3
- package/dist/user-connect/connection-code.d.ts +1 -1
- package/dist/user-connect/connection-code.js +7 -7
- package/dist/user-connect/connection-code.test.js +106 -106
- package/dist/user-connect/index.d.ts +3 -3
- package/dist/user-connect/index.js +1 -1
- package/dist/user-connect/user-connect.pvars.js +13 -11
- package/dist/user-connect/user-connect.types.d.ts +3 -3
- package/dist/users.query.d.ts +2 -2
- package/dist/users.query.js +40 -30
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +34 -32
- package/dist/utils.test.js +12 -8
- package/dist/workflow-log-formatter.d.ts +1 -1
- package/dist/workflow-log-formatter.js +17 -18
- package/package.json +14 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Table } from "./orm/table";
|
|
2
1
|
import { z } from "zod";
|
|
3
|
-
import { IDataLock } from "./data-locks";
|
|
4
2
|
import type { DataContext } from "../context/data-context";
|
|
3
|
+
import { type IDataLock } from "./data-locks";
|
|
4
|
+
import { Table } from "./orm/table";
|
|
5
5
|
export declare const workflowRunSchema: z.ZodObject<{
|
|
6
6
|
workflowRunId: z.ZodEffects<z.ZodString, string, string>;
|
|
7
7
|
workflowId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
@@ -33,6 +33,7 @@ export declare const workflowRunSchema: z.ZodObject<{
|
|
|
33
33
|
parentWorkflowRunId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
34
34
|
defaultAssistantId: z.ZodEffects<z.ZodString, string, string>;
|
|
35
35
|
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
createdAt: Date;
|
|
36
37
|
defaultAssistantId: string;
|
|
37
38
|
instructions: {
|
|
38
39
|
markdown?: string | undefined;
|
|
@@ -40,7 +41,6 @@ export declare const workflowRunSchema: z.ZodObject<{
|
|
|
40
41
|
directCallToolId?: string | undefined;
|
|
41
42
|
subWorkflowId?: string | undefined;
|
|
42
43
|
}[];
|
|
43
|
-
createdAt: Date;
|
|
44
44
|
workflowRunId: string;
|
|
45
45
|
parentMessageId: string;
|
|
46
46
|
currentInstructionIndex: number;
|
|
@@ -58,6 +58,7 @@ export declare const workflowRunSchema: z.ZodObject<{
|
|
|
58
58
|
defaultAssistantId: string;
|
|
59
59
|
workflowRunId: string;
|
|
60
60
|
parentMessageId: string;
|
|
61
|
+
createdAt?: Date | undefined;
|
|
61
62
|
workflowId?: string | undefined;
|
|
62
63
|
instructions?: {
|
|
63
64
|
markdown?: string | undefined;
|
|
@@ -65,7 +66,6 @@ export declare const workflowRunSchema: z.ZodObject<{
|
|
|
65
66
|
directCallToolId?: string | undefined;
|
|
66
67
|
subWorkflowId?: string | undefined;
|
|
67
68
|
}[] | undefined;
|
|
68
|
-
createdAt?: Date | undefined;
|
|
69
69
|
scheduleDT?: Date | undefined;
|
|
70
70
|
currentInstructionIndex?: number | undefined;
|
|
71
71
|
instructionResults?: any[] | undefined;
|
|
@@ -78,9 +78,9 @@ export declare const workflowRunSchema: z.ZodObject<{
|
|
|
78
78
|
export type IWorkflowRun = z.infer<typeof workflowRunSchema>;
|
|
79
79
|
declare class WorkflowRunTable extends Table<IWorkflowRun> {
|
|
80
80
|
/** @deprecated Direct calls to save forbidden; use insert or saveWithLock */
|
|
81
|
-
save(..._args: Parameters<Table<any>[
|
|
81
|
+
save(..._args: Parameters<Table<any>["insert"]>): never;
|
|
82
82
|
/** @deprecated Direct calls to update forbidden; use saveWithLock() */
|
|
83
|
-
update(..._args: Parameters<Table<any>[
|
|
83
|
+
update(..._args: Parameters<Table<any>["update"]>): never;
|
|
84
84
|
saveWithLock(workflowRun: IWorkflowRun, lock?: IDataLock): Promise<IWorkflowRun>;
|
|
85
85
|
acquireLock(workflowRunId: string, timeoutMs?: number, lockTimeMs?: number): Promise<IDataLock | undefined>;
|
|
86
86
|
saveAndRelease(workflowRun: IWorkflowRun, lock: IDataLock): Promise<void>;
|
|
@@ -38,52 +38,78 @@ exports.workflowRunSchema = void 0;
|
|
|
38
38
|
exports.WorkflowRuns = WorkflowRuns;
|
|
39
39
|
exports.runWorkflow = runWorkflow;
|
|
40
40
|
const moment = require("moment-timezone");
|
|
41
|
+
const zod_1 = require("zod");
|
|
42
|
+
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
43
|
+
const mentions_1 = require("../mentions");
|
|
44
|
+
const system_ids_1 = require("../system-ids");
|
|
45
|
+
const workflow_1 = require("../types/workflow");
|
|
46
|
+
const zod_types_1 = require("../types/zod-types");
|
|
47
|
+
const utils_1 = require("../utils");
|
|
48
|
+
const assistants_1 = require("./assistants");
|
|
41
49
|
const channels_1 = require("./channels");
|
|
50
|
+
const data_locks_1 = require("./data-locks");
|
|
42
51
|
const groups_1 = require("./groups");
|
|
43
52
|
const messages_1 = require("./messages");
|
|
53
|
+
const orm_1 = require("./orm");
|
|
44
54
|
const table_1 = require("./orm/table");
|
|
55
|
+
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
45
56
|
const types_1 = require("./orm/types");
|
|
46
57
|
const users_1 = require("./users");
|
|
47
58
|
const workflow_logs_1 = require("./workflow-logs");
|
|
48
59
|
const workflows_1 = require("./workflows");
|
|
49
|
-
const utils_1 = require("../utils");
|
|
50
|
-
const mentions_1 = require("../mentions");
|
|
51
|
-
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
52
|
-
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
53
|
-
const zod_1 = require("zod");
|
|
54
|
-
const workflow_1 = require("../types/workflow");
|
|
55
|
-
const zod_types_1 = require("../types/zod-types");
|
|
56
|
-
const data_locks_1 = require("./data-locks");
|
|
57
|
-
const assistants_1 = require("./assistants");
|
|
58
|
-
const system_ids_1 = require("../system-ids");
|
|
59
|
-
const orm_1 = require("./orm");
|
|
60
60
|
exports.workflowRunSchema = zod_1.z.object({
|
|
61
61
|
workflowRunId: zod_types_1.zodPeerId,
|
|
62
|
-
workflowId: zod_types_1.zodPeerId.optional().describe(
|
|
63
|
-
parentMessageId: zod_types_1.zodPeerId.describe(
|
|
64
|
-
createdAt: zod_1.z
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
62
|
+
workflowId: zod_types_1.zodPeerId.optional().describe("The workflow that is being run. "),
|
|
63
|
+
parentMessageId: zod_types_1.zodPeerId.describe("The message that this workflow will run in the context of"),
|
|
64
|
+
createdAt: zod_1.z
|
|
65
|
+
.date()
|
|
66
|
+
.default(() => new Date())
|
|
67
|
+
.describe("The date the workflow run was created"),
|
|
68
|
+
scheduleDT: zod_1.z
|
|
69
|
+
.date()
|
|
70
|
+
.optional()
|
|
71
|
+
.describe("The date and time that the workflow run is scheduled to run"),
|
|
72
|
+
instructions: workflow_1.workflowInstructionSchema
|
|
73
|
+
.array()
|
|
74
|
+
.default([])
|
|
75
|
+
.describe("The remaining instructions that still need to be done. The LLM can use this as a scratch pad, adding and removing instructions as needed."),
|
|
76
|
+
currentInstructionIndex: zod_1.z
|
|
77
|
+
.number()
|
|
78
|
+
.default(0)
|
|
79
|
+
.describe("The index of the current instruction that is being run"),
|
|
80
|
+
instructionResults: zod_1.z
|
|
81
|
+
.any()
|
|
82
|
+
.array()
|
|
83
|
+
.default([])
|
|
84
|
+
.describe("The results of the instructions that have been run."),
|
|
85
|
+
inErrorState: zod_1.z
|
|
86
|
+
.boolean()
|
|
87
|
+
.optional()
|
|
88
|
+
.describe("Whether or not the workflow run is in an error state"),
|
|
89
|
+
startedAt: zod_1.z
|
|
90
|
+
.date()
|
|
91
|
+
.optional()
|
|
92
|
+
.describe("The date the workflow run first started to be processed"),
|
|
93
|
+
completedAt: zod_1.z.date().optional().describe("The date the workflow run was completed"),
|
|
94
|
+
vars: zod_types_1.zodAnyObject
|
|
95
|
+
.default(() => ({}))
|
|
96
|
+
.describe(`The current value of the workflow run. This is a scratch pad that the LLM can use to store values that are needed for the workflow run.`),
|
|
97
|
+
parentWorkflowRunId: zod_types_1.zodPeerId
|
|
98
|
+
.optional()
|
|
99
|
+
.describe("The parent workflow run id if this is a sub workflow run"),
|
|
100
|
+
defaultAssistantId: zod_types_1.zodPeerId.describe("The default assistant to use for this workflow run"),
|
|
75
101
|
});
|
|
76
102
|
const metaData = {
|
|
77
|
-
name:
|
|
78
|
-
description:
|
|
79
|
-
primaryKeyName:
|
|
103
|
+
name: "WorkflowRuns",
|
|
104
|
+
description: "workflows instances that have been run manually, from messages, or from events",
|
|
105
|
+
primaryKeyName: "workflowRunId",
|
|
80
106
|
fields: (0, types_1.schemaToFields)(exports.workflowRunSchema),
|
|
81
107
|
indexes: [
|
|
82
|
-
{ fields: [
|
|
83
|
-
{ fields: [
|
|
84
|
-
{ fields: [
|
|
85
|
-
{ fields: [
|
|
86
|
-
{ fields: [
|
|
108
|
+
{ fields: ["workflowId"] },
|
|
109
|
+
{ fields: ["parentMessageId"] },
|
|
110
|
+
{ fields: ["parentWorkflowRunId"] },
|
|
111
|
+
{ fields: ["completedAt"] },
|
|
112
|
+
{ fields: ["inErrorState"] },
|
|
87
113
|
],
|
|
88
114
|
};
|
|
89
115
|
let WorkflowRunTable = (() => {
|
|
@@ -99,11 +125,11 @@ let WorkflowRunTable = (() => {
|
|
|
99
125
|
}
|
|
100
126
|
/** @deprecated Direct calls to save forbidden; use insert or saveWithLock */
|
|
101
127
|
save(..._args) {
|
|
102
|
-
throw new Error(
|
|
128
|
+
throw new Error("Direct inserts forbidden; use insert() or saveWithLock()");
|
|
103
129
|
}
|
|
104
130
|
/** @deprecated Direct calls to update forbidden; use saveWithLock() */
|
|
105
131
|
update(..._args) {
|
|
106
|
-
throw new Error(
|
|
132
|
+
throw new Error("Direct updates forbidden; use saveWithLock()");
|
|
107
133
|
}
|
|
108
134
|
async saveWithLock(workflowRun, lock) {
|
|
109
135
|
if (!workflowRun.workflowRunId) {
|
|
@@ -197,11 +223,13 @@ let WorkflowRunTable = (() => {
|
|
|
197
223
|
}
|
|
198
224
|
}
|
|
199
225
|
// also halt any child runs
|
|
200
|
-
this.list({ parentWorkflowRunId: workflowRunId })
|
|
226
|
+
this.list({ parentWorkflowRunId: workflowRunId })
|
|
227
|
+
.then(async (childRuns) => {
|
|
201
228
|
childRuns.forEach(async (child) => {
|
|
202
229
|
this.haltRun(child.workflowRunId).catch((err) => console.error(`Error halting child run ${child.workflowRunId}`, err));
|
|
203
230
|
});
|
|
204
|
-
})
|
|
231
|
+
})
|
|
232
|
+
.catch((err) => console.error(`Error halting child runs for ${workflowRunId}`, err));
|
|
205
233
|
// send message and log
|
|
206
234
|
const runHaltMessage = `Workflow run canceled at ${new Date().toISOString()}`;
|
|
207
235
|
await (0, messages_1.sendMessage)({
|
|
@@ -247,19 +275,17 @@ function WorkflowRuns(dataContext) {
|
|
|
247
275
|
}
|
|
248
276
|
async function runWorkflow(args) {
|
|
249
277
|
const { workflowId, parentWorkflowRunId, vars } = args;
|
|
250
|
-
// TODO determine what dataContext this is for
|
|
278
|
+
// TODO determine what dataContext this is for
|
|
251
279
|
const workflow = await (0, workflows_1.Workflows)().get(workflowId);
|
|
252
280
|
if (!workflow) {
|
|
253
281
|
throw new Error(`Workflow ${workflowId} not found`);
|
|
254
282
|
}
|
|
255
283
|
const me = await (0, users_1.getMe)();
|
|
256
|
-
const assistantId = workflow.defaultAssistantId
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
let parentMessageId = '';
|
|
260
|
-
let channelId = '';
|
|
284
|
+
const assistantId = workflow.defaultAssistantId || (await (0, assistants_1.getPrimaryAssistant)()).assistantId || system_ids_1.defaultAssistantId;
|
|
285
|
+
let parentMessageId = "";
|
|
286
|
+
let channelId = "";
|
|
261
287
|
if (args.parentMessageIdOrChannelIdOrGroupId) {
|
|
262
|
-
|
|
288
|
+
const message = await (0, messages_1.Messages)().get(args.parentMessageIdOrChannelIdOrGroupId);
|
|
263
289
|
if (message) {
|
|
264
290
|
parentMessageId = message.messageId;
|
|
265
291
|
channelId = message.channelId;
|
|
@@ -277,7 +303,7 @@ async function runWorkflow(args) {
|
|
|
277
303
|
}
|
|
278
304
|
}
|
|
279
305
|
const workflowRunId = (0, utils_1.newid)();
|
|
280
|
-
const workflowMention = (0, mentions_1.formatMention)({ kind:
|
|
306
|
+
const workflowMention = (0, mentions_1.formatMention)({ kind: "workflow", id: workflowId, name: workflow.name });
|
|
281
307
|
let messageContent = `Running workflow ${workflowMention}`;
|
|
282
308
|
if (!parentMessageId) {
|
|
283
309
|
if (!channelId) {
|
package/dist/data/workflows.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { DataContext } from "../context/data-context";
|
|
|
2
2
|
export declare function Workflows(dataContext?: DataContext): import("./orm").Table<{
|
|
3
3
|
name: string;
|
|
4
4
|
description: string;
|
|
5
|
+
createdBy: string;
|
|
6
|
+
createdAt: Date;
|
|
5
7
|
workflowId: string;
|
|
6
8
|
defaultAssistantId: string;
|
|
7
9
|
instructions: {
|
|
@@ -10,7 +12,5 @@ export declare function Workflows(dataContext?: DataContext): import("./orm").Ta
|
|
|
10
12
|
directCallToolId?: string | undefined;
|
|
11
13
|
subWorkflowId?: string | undefined;
|
|
12
14
|
}[];
|
|
13
|
-
createdBy: string;
|
|
14
|
-
createdAt: Date;
|
|
15
15
|
updatedAt: Date;
|
|
16
16
|
}>;
|
package/dist/data/workflows.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Workflows = Workflows;
|
|
4
|
-
const workflow_1 = require("../types/workflow");
|
|
5
|
-
const types_1 = require("./orm/types");
|
|
6
4
|
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
5
|
+
const workflow_1 = require("../types/workflow");
|
|
7
6
|
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
7
|
+
const types_1 = require("./orm/types");
|
|
8
8
|
const metaData = {
|
|
9
|
-
name:
|
|
10
|
-
description:
|
|
11
|
-
primaryKeyName:
|
|
9
|
+
name: "Workflows",
|
|
10
|
+
description: "workflows",
|
|
11
|
+
primaryKeyName: "workflowId",
|
|
12
12
|
fields: (0, types_1.schemaToFields)(workflow_1.workflowSchema),
|
|
13
|
-
iconClassName:
|
|
14
|
-
indexes: [
|
|
15
|
-
{ fields: ['name'], },
|
|
16
|
-
],
|
|
13
|
+
iconClassName: "bi bi-database-fill-gear",
|
|
14
|
+
indexes: [{ fields: ["name"] }],
|
|
17
15
|
};
|
|
18
16
|
(0, table_definitions_system_1.registerSystemTableDefinition)(metaData, workflow_1.workflowSchema);
|
|
19
17
|
function Workflows(dataContext) {
|
|
@@ -16,17 +16,17 @@
|
|
|
16
16
|
* and event-loop yielding (critical for Go sidecar WebRTC pipeline).
|
|
17
17
|
*/
|
|
18
18
|
import { Connection } from "./connection";
|
|
19
|
-
import { Device } from "./device";
|
|
20
|
-
import { ISocket } from "./socket.type";
|
|
21
|
-
type ITrustLevelFn = Connection[
|
|
19
|
+
import type { Device } from "./device";
|
|
20
|
+
import { type ISocket } from "./socket.type";
|
|
21
|
+
type ITrustLevelFn = Connection["getTrustLevel"];
|
|
22
22
|
/**
|
|
23
23
|
* Generic binary peer interface supporting WebRTC and WebSocket transports.
|
|
24
24
|
* Provides a unified abstraction for binary data channel communication.
|
|
25
25
|
*/
|
|
26
26
|
export interface IBinaryPeer {
|
|
27
|
-
on(event:
|
|
28
|
-
on(event:
|
|
29
|
-
on(event:
|
|
27
|
+
on(event: "data", handler: (data: Buffer | Uint8Array) => void): void;
|
|
28
|
+
on(event: "close", handler: () => void): void;
|
|
29
|
+
on(event: "drain", handler: () => void): void;
|
|
30
30
|
send(data: string | Uint8Array | Buffer): void;
|
|
31
31
|
destroy(): void;
|
|
32
32
|
/**
|
|
@@ -38,7 +38,7 @@ export interface IBinaryPeer {
|
|
|
38
38
|
export type IWebRTCPeer = IBinaryPeer;
|
|
39
39
|
export interface WrapBinaryPeerOptions {
|
|
40
40
|
/** Protocol identifier used for server address (e.g., 'wrtc' or 'ws') */
|
|
41
|
-
protocol:
|
|
41
|
+
protocol: "wrtc" | "ws";
|
|
42
42
|
/**
|
|
43
43
|
* Mark the transport as already secure (encrypted at transport layer).
|
|
44
44
|
* When true, sets secureLocal and secureRemote to skip application-level encryption.
|
|
@@ -21,10 +21,10 @@ exports.createBinaryPeerSocket = createBinaryPeerSocket;
|
|
|
21
21
|
exports.wrapBinaryPeer = wrapBinaryPeer;
|
|
22
22
|
exports.wrapWrtc = wrapWrtc;
|
|
23
23
|
const msgpack_1 = require("@msgpack/msgpack");
|
|
24
|
+
const utils_1 = require("../utils");
|
|
24
25
|
const connection_1 = require("./connection");
|
|
25
26
|
const get_trust_level_fn_1 = require("./get-trust-level-fn");
|
|
26
27
|
const socket_type_1 = require("./socket.type");
|
|
27
|
-
const utils_1 = require("../utils");
|
|
28
28
|
const tx_encoding_1 = require("./tx-encoding");
|
|
29
29
|
// ─── Wire Protocol Frame Types ───────────────────────────────────────
|
|
30
30
|
// RPC frames
|
|
@@ -49,9 +49,12 @@ const WS_CONFIG = {
|
|
|
49
49
|
};
|
|
50
50
|
function getTransportConfig(protocol) {
|
|
51
51
|
switch (protocol) {
|
|
52
|
-
case
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
case "wrtc":
|
|
53
|
+
return WRTC_CONFIG;
|
|
54
|
+
case "ws":
|
|
55
|
+
return WS_CONFIG;
|
|
56
|
+
default:
|
|
57
|
+
return WS_CONFIG;
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
// ─── Stream ID Caching ───────────────────────────────────────────────
|
|
@@ -84,10 +87,10 @@ function decodeStreamId(bytes) {
|
|
|
84
87
|
}
|
|
85
88
|
function encodeMessage(message) {
|
|
86
89
|
let isUint8ArrayData = false;
|
|
87
|
-
if (message.type ===
|
|
90
|
+
if (message.type === "call" && message.args instanceof Uint8Array) {
|
|
88
91
|
isUint8ArrayData = true;
|
|
89
92
|
}
|
|
90
|
-
else if (message.type ===
|
|
93
|
+
else if (message.type === "callback" && message.result instanceof Uint8Array) {
|
|
91
94
|
isUint8ArrayData = true;
|
|
92
95
|
}
|
|
93
96
|
const metadata = {
|
|
@@ -99,7 +102,7 @@ function encodeMessage(message) {
|
|
|
99
102
|
const metadataBytes = (0, msgpack_1.encode)(metadata);
|
|
100
103
|
const metadataLength = metadataBytes.length;
|
|
101
104
|
let dataBytes;
|
|
102
|
-
if (message.type ===
|
|
105
|
+
if (message.type === "call" && message.args !== undefined) {
|
|
103
106
|
if (isUint8ArrayData) {
|
|
104
107
|
dataBytes = message.args;
|
|
105
108
|
}
|
|
@@ -107,7 +110,7 @@ function encodeMessage(message) {
|
|
|
107
110
|
dataBytes = (0, tx_encoding_1.txEncode)(message.args);
|
|
108
111
|
}
|
|
109
112
|
}
|
|
110
|
-
else if (message.type ===
|
|
113
|
+
else if (message.type === "callback") {
|
|
111
114
|
if (message.error !== undefined) {
|
|
112
115
|
dataBytes = (0, tx_encoding_1.txEncode)({ error: message.error });
|
|
113
116
|
}
|
|
@@ -140,7 +143,7 @@ function decodeMessage(bytes) {
|
|
|
140
143
|
eventName: metadata.eventName,
|
|
141
144
|
};
|
|
142
145
|
if (dataBytes.length > 0) {
|
|
143
|
-
if (message.type ===
|
|
146
|
+
if (message.type === "call") {
|
|
144
147
|
if (metadata.isUint8ArrayData) {
|
|
145
148
|
message.args = dataBytes;
|
|
146
149
|
}
|
|
@@ -148,7 +151,7 @@ function decodeMessage(bytes) {
|
|
|
148
151
|
message.args = (0, tx_encoding_1.txDecode)(dataBytes);
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
|
-
else if (message.type ===
|
|
154
|
+
else if (message.type === "callback") {
|
|
152
155
|
if (metadata.isUint8ArrayData) {
|
|
153
156
|
message.result = dataBytes;
|
|
154
157
|
}
|
|
@@ -224,19 +227,18 @@ function buildStreamCont(sidBytes, chunkData) {
|
|
|
224
227
|
* Creates an ISocket from a binary peer. This is the core v2 factory function.
|
|
225
228
|
* Replaces both createBinaryPeerSocket (v1) and StreamedSocket.
|
|
226
229
|
*/
|
|
227
|
-
function createBinaryPeerSocket(connectionId, peer, protocol =
|
|
230
|
+
function createBinaryPeerSocket(connectionId, peer, protocol = "binary") {
|
|
228
231
|
const handlers = {};
|
|
229
232
|
const callbacks = {};
|
|
230
233
|
const rawBytesHandlers = {};
|
|
231
234
|
let isClosed = false;
|
|
232
235
|
const stats = (0, socket_type_1.createSocketStats)();
|
|
233
|
-
const transportType = protocol ===
|
|
234
|
-
protocol === 'ws' ? 'ws' : 'unknown';
|
|
236
|
+
const transportType = protocol === "wrtc" ? "wrtc" : protocol === "ws" ? "ws" : "unknown";
|
|
235
237
|
const config = getTransportConfig(protocol);
|
|
236
238
|
// ─── Drain / Backpressure ────────────────────────────────────────
|
|
237
239
|
// Single persistent drain handler to avoid leaking listeners
|
|
238
240
|
let drainResolve = null;
|
|
239
|
-
peer.on(
|
|
241
|
+
peer.on("drain", () => {
|
|
240
242
|
if (drainResolve) {
|
|
241
243
|
const resolve = drainResolve;
|
|
242
244
|
drainResolve = null;
|
|
@@ -250,7 +252,7 @@ function createBinaryPeerSocket(connectionId, peer, protocol = 'binary') {
|
|
|
250
252
|
async function sendFrame(frame) {
|
|
251
253
|
// Backpressure: wait for buffer to drain before sending more
|
|
252
254
|
while ((peer.getBufferedAmount?.() ?? 0) > config.highWaterMark) {
|
|
253
|
-
await new Promise(resolve => {
|
|
255
|
+
await new Promise((resolve) => {
|
|
254
256
|
drainResolve = resolve;
|
|
255
257
|
// Also poll as fallback (drain event might not fire on all transports)
|
|
256
258
|
const timer = setInterval(() => {
|
|
@@ -270,7 +272,7 @@ function createBinaryPeerSocket(connectionId, peer, protocol = 'binary') {
|
|
|
270
272
|
// in a microtask chain that starves the Unix socket I/O, deadlocking
|
|
271
273
|
// at ~1MB total data.
|
|
272
274
|
if (config.yieldBetweenChunks) {
|
|
273
|
-
await new Promise(resolve => setImmediate(resolve));
|
|
275
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
274
276
|
}
|
|
275
277
|
}
|
|
276
278
|
// ─── RPC Engine ──────────────────────────────────────────────────
|
|
@@ -313,7 +315,7 @@ function createBinaryPeerSocket(connectionId, peer, protocol = 'binary') {
|
|
|
313
315
|
const rpcReassemblyBuffers = new Map();
|
|
314
316
|
function handleIncomingRPC(bytes) {
|
|
315
317
|
const message = decodeMessage(bytes);
|
|
316
|
-
if (message.type ===
|
|
318
|
+
if (message.type === "callback") {
|
|
317
319
|
const callback = callbacks[message.callbackId];
|
|
318
320
|
if (callback) {
|
|
319
321
|
delete callbacks[message.callbackId];
|
|
@@ -321,7 +323,7 @@ function createBinaryPeerSocket(connectionId, peer, protocol = 'binary') {
|
|
|
321
323
|
}
|
|
322
324
|
return;
|
|
323
325
|
}
|
|
324
|
-
if (message.type ===
|
|
326
|
+
if (message.type === "call") {
|
|
325
327
|
const handler = handlers[message.eventName];
|
|
326
328
|
if (!handler) {
|
|
327
329
|
console.warn(`No handler for event: ${message.eventName}`);
|
|
@@ -330,7 +332,7 @@ function createBinaryPeerSocket(connectionId, peer, protocol = 'binary') {
|
|
|
330
332
|
try {
|
|
331
333
|
const callback = (err, result) => {
|
|
332
334
|
const responseMessage = {
|
|
333
|
-
type:
|
|
335
|
+
type: "callback",
|
|
334
336
|
callbackId: message.callbackId,
|
|
335
337
|
};
|
|
336
338
|
if (err)
|
|
@@ -345,9 +347,9 @@ function createBinaryPeerSocket(connectionId, peer, protocol = 'binary') {
|
|
|
345
347
|
catch (error) {
|
|
346
348
|
console.error("Error in handler", { eventName: message.eventName, error });
|
|
347
349
|
const errorMessage = {
|
|
348
|
-
type:
|
|
350
|
+
type: "callback",
|
|
349
351
|
callbackId: message.callbackId,
|
|
350
|
-
error: error.message
|
|
352
|
+
error: error.message,
|
|
351
353
|
};
|
|
352
354
|
const encoded = encodeMessage(errorMessage);
|
|
353
355
|
sendRPC(encoded);
|
|
@@ -383,7 +385,7 @@ function createBinaryPeerSocket(connectionId, peer, protocol = 'binary') {
|
|
|
383
385
|
}
|
|
384
386
|
}
|
|
385
387
|
// ─── Incoming Frame Router ───────────────────────────────────────
|
|
386
|
-
peer.on(
|
|
388
|
+
peer.on("data", (data) => {
|
|
387
389
|
try {
|
|
388
390
|
const bytes = new Uint8Array(data);
|
|
389
391
|
stats.bytesReceived += bytes.length;
|
|
@@ -510,7 +512,7 @@ function createBinaryPeerSocket(connectionId, peer, protocol = 'binary') {
|
|
|
510
512
|
}
|
|
511
513
|
});
|
|
512
514
|
// Handle closure
|
|
513
|
-
peer.on(
|
|
515
|
+
peer.on("close", () => {
|
|
514
516
|
if (isClosed)
|
|
515
517
|
return;
|
|
516
518
|
isClosed = true;
|
|
@@ -526,7 +528,7 @@ function createBinaryPeerSocket(connectionId, peer, protocol = 'binary') {
|
|
|
526
528
|
emit(eventName, args, callback) {
|
|
527
529
|
const callbackId = (0, utils_1.newid)();
|
|
528
530
|
callbacks[callbackId] = callback;
|
|
529
|
-
const message = { type:
|
|
531
|
+
const message = { type: "call", eventName, args, callbackId };
|
|
530
532
|
const encoded = encodeMessage(message);
|
|
531
533
|
sendRPC(encoded);
|
|
532
534
|
},
|
|
@@ -538,7 +540,9 @@ function createBinaryPeerSocket(connectionId, peer, protocol = 'binary') {
|
|
|
538
540
|
delete handlers[eventName];
|
|
539
541
|
}
|
|
540
542
|
else {
|
|
541
|
-
Object.keys(handlers)
|
|
543
|
+
for (const key of Object.keys(handlers)) {
|
|
544
|
+
delete handlers[key];
|
|
545
|
+
}
|
|
542
546
|
}
|
|
543
547
|
},
|
|
544
548
|
disconnect() {
|
|
@@ -550,7 +554,7 @@ function createBinaryPeerSocket(connectionId, peer, protocol = 'binary') {
|
|
|
550
554
|
},
|
|
551
555
|
removeRawBytesHandler(streamId) {
|
|
552
556
|
delete rawBytesHandlers[streamId];
|
|
553
|
-
}
|
|
557
|
+
},
|
|
554
558
|
};
|
|
555
559
|
return socket;
|
|
556
560
|
}
|
|
@@ -564,7 +568,7 @@ function wrapBinaryPeer(connectionId, peer, localDevice, initiator, options, get
|
|
|
564
568
|
const socket = createBinaryPeerSocket(connectionId, peer, protocol);
|
|
565
569
|
const serverAddress = `${protocol}://${connectionId}`;
|
|
566
570
|
const localServerAddresses = initiator ? undefined : [serverAddress];
|
|
567
|
-
if (process.env.NODE_ENV !==
|
|
571
|
+
if (process.env.NODE_ENV !== "test") {
|
|
568
572
|
getTrustLevel ??= (0, get_trust_level_fn_1.getTrustLevelFn)(localDevice, serverAddress);
|
|
569
573
|
}
|
|
570
574
|
const connection = new connection_1.Connection(socket, localDevice, localServerAddresses, getTrustLevel);
|
|
@@ -579,5 +583,5 @@ function wrapBinaryPeer(connectionId, peer, localDevice, initiator, options, get
|
|
|
579
583
|
* WebRTC is encrypted at the transport layer (DTLS-SRTP).
|
|
580
584
|
*/
|
|
581
585
|
function wrapWrtc(connectionId, peer, localDevice, initiator, getTrustLevel) {
|
|
582
|
-
return wrapBinaryPeer(connectionId, peer, localDevice, initiator, { protocol:
|
|
586
|
+
return wrapBinaryPeer(connectionId, peer, localDevice, initiator, { protocol: "wrtc", markTransportSecure: true }, getTrustLevel);
|
|
583
587
|
}
|