@peers-app/peers-sdk 0.11.1 → 0.12.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.
@@ -30,6 +30,7 @@ export * from "./tools";
30
30
  export * from "./users";
31
31
  export * from "./user-permissions";
32
32
  export * from "./user-trust-levels";
33
+ export * from "./voice-messages";
33
34
  export * from "./welcome-modal.pvar";
34
35
  export * from "./workflow-logs";
35
36
  export * from "./workflow-runs";
@@ -46,6 +46,7 @@ __exportStar(require("./tools"), exports);
46
46
  __exportStar(require("./users"), exports);
47
47
  __exportStar(require("./user-permissions"), exports);
48
48
  __exportStar(require("./user-trust-levels"), exports);
49
+ __exportStar(require("./voice-messages"), exports);
49
50
  __exportStar(require("./welcome-modal.pvar"), exports);
50
51
  __exportStar(require("./workflow-logs"), exports);
51
52
  __exportStar(require("./workflow-runs"), exports);
@@ -6,6 +6,7 @@ exports.sendMessage = sendMessage;
6
6
  exports.getThreadVars = getThreadVars;
7
7
  const types_1 = require("./orm/types");
8
8
  const users_1 = require("./users");
9
+ const groups_1 = require("./groups");
9
10
  const channels_1 = require("./channels");
10
11
  const workflow_runs_1 = require("./workflow-runs");
11
12
  const utils_1 = require("../utils");
@@ -59,10 +60,14 @@ async function sendMessage(args) {
59
60
  else {
60
61
  const channel = await (0, channels_1.Channels)().get(channelOrThreadIdOrWorkflowRunId);
61
62
  if (!channel) {
62
- // check if channel is a user id
63
- const user = await (0, users_1.Users)().get(channelOrThreadIdOrWorkflowRunId);
64
- if (!user) {
65
- throw new Error(`Channel ${channelOrThreadIdOrWorkflowRunId} not found. A channel must be a valid channelId or userId or groupId.`);
63
+ // check if it's a group id (group id doubles as its default channel id)
64
+ const group = await (0, groups_1.Groups)().get(channelOrThreadIdOrWorkflowRunId);
65
+ if (!group) {
66
+ // check if channel is a user id
67
+ const user = await (0, users_1.Users)().get(channelOrThreadIdOrWorkflowRunId);
68
+ if (!user) {
69
+ throw new Error(`Channel ${channelOrThreadIdOrWorkflowRunId} not found. A channel must be a valid channelId or userId or groupId.`);
70
+ }
66
71
  }
67
72
  }
68
73
  }
@@ -7,7 +7,6 @@ declare const schema: z.ZodObject<{
7
7
  name: z.ZodString;
8
8
  description: z.ZodString;
9
9
  createdBy: z.ZodEffects<z.ZodString, string, string>;
10
- localPath: z.ZodString;
11
10
  disabled: z.ZodOptional<z.ZodBoolean>;
12
11
  remoteRepo: z.ZodOptional<z.ZodString>;
13
12
  appNavs: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -36,7 +35,6 @@ declare const schema: z.ZodObject<{
36
35
  signature: string;
37
36
  createdBy: string;
38
37
  packageId: string;
39
- localPath: string;
40
38
  disabled?: boolean | undefined;
41
39
  appNavs?: {
42
40
  name: string;
@@ -54,7 +52,6 @@ declare const schema: z.ZodObject<{
54
52
  signature: string;
55
53
  createdBy: string;
56
54
  packageId: string;
57
- localPath: string;
58
55
  disabled?: boolean | undefined;
59
56
  appNavs?: {
60
57
  name: string;
@@ -51,7 +51,6 @@ const schema = zod_1.z.object({
51
51
  name: zod_1.z.string(),
52
52
  description: zod_1.z.string(),
53
53
  createdBy: zod_types_1.zodPeerId.describe('The user who created the package'),
54
- localPath: zod_1.z.string().describe('The local path where the package is stored'),
55
54
  disabled: zod_1.z.boolean().optional().describe("Whether the package's components should be loaded and included in the app runtime"),
56
55
  remoteRepo: zod_1.z.string().optional().describe('The remote repository where the package is stored'),
57
56
  appNavs: app_nav_1.appNavSchema.array().optional().describe('The app navigation items that this package provides'),
@@ -0,0 +1,33 @@
1
+ import { z } from 'zod';
2
+ import { DataContext } from '../context/data-context';
3
+ export declare const voiceMessageSchema: z.ZodObject<{
4
+ voiceMessageId: z.ZodDefault<z.ZodEffects<z.ZodString, string, string>>;
5
+ sessionId: z.ZodString;
6
+ role: z.ZodEnum<["user", "assistant"]>;
7
+ content: z.ZodString;
8
+ threadId: z.ZodOptional<z.ZodString>;
9
+ createdAt: z.ZodDefault<z.ZodDate>;
10
+ }, "strip", z.ZodTypeAny, {
11
+ content: string;
12
+ role: "user" | "assistant";
13
+ createdAt: Date;
14
+ voiceMessageId: string;
15
+ sessionId: string;
16
+ threadId?: string | undefined;
17
+ }, {
18
+ content: string;
19
+ role: "user" | "assistant";
20
+ sessionId: string;
21
+ createdAt?: Date | undefined;
22
+ voiceMessageId?: string | undefined;
23
+ threadId?: string | undefined;
24
+ }>;
25
+ export type IVoiceMessage = z.infer<typeof voiceMessageSchema>;
26
+ export declare function VoiceMessages(dataContext?: DataContext): import("./orm").Table<{
27
+ content: string;
28
+ role: "user" | "assistant";
29
+ createdAt: Date;
30
+ voiceMessageId: string;
31
+ sessionId: string;
32
+ threadId?: string | undefined;
33
+ }>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.voiceMessageSchema = void 0;
4
+ exports.VoiceMessages = VoiceMessages;
5
+ const types_1 = require("./orm/types");
6
+ const utils_1 = require("../utils");
7
+ const zod_1 = require("zod");
8
+ const zod_types_1 = require("../types/zod-types");
9
+ const user_context_singleton_1 = require("../context/user-context-singleton");
10
+ const table_definitions_system_1 = require("./orm/table-definitions.system");
11
+ exports.voiceMessageSchema = zod_1.z.object({
12
+ voiceMessageId: zod_types_1.zodPeerId.default(() => (0, utils_1.newid)()),
13
+ sessionId: zod_1.z.string().describe('Groups messages belonging to one voice session'),
14
+ role: zod_1.z.enum(['user', 'assistant']),
15
+ content: zod_1.z.string(),
16
+ threadId: zod_1.z.string().optional().describe('messageId of the channel thread created when an action was dispatched to the background agent'),
17
+ createdAt: zod_1.z.date().default(() => new Date()),
18
+ });
19
+ const metaData = {
20
+ name: 'VoiceMessages',
21
+ description: 'Voice conversation history for the self-contained voice assistant',
22
+ primaryKeyName: 'voiceMessageId',
23
+ fields: (0, types_1.schemaToFields)(exports.voiceMessageSchema),
24
+ localOnly: true,
25
+ indexes: [
26
+ { fields: ['sessionId'] },
27
+ { fields: ['sessionId', 'createdAt'] },
28
+ ],
29
+ };
30
+ (0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.voiceMessageSchema);
31
+ function VoiceMessages(dataContext) {
32
+ return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, exports.voiceMessageSchema);
33
+ }
@@ -13,6 +13,7 @@ export declare class PackageLoader {
13
13
  }): Promise<void>;
14
14
  loadPackage(pkg: IPackage, opts?: {
15
15
  force?: boolean;
16
+ localPath?: string;
16
17
  }): Promise<IPeersPackage | undefined>;
17
18
  private _readLocalBundle;
18
19
  private _evaluateBundle;
@@ -29,6 +29,7 @@ class PackageLoader {
29
29
  if (this.packageInstances[pkg.packageId] && !opts?.force) {
30
30
  return this.packageInstances[pkg.packageId];
31
31
  }
32
+ const localPath = opts?.localPath;
32
33
  try {
33
34
  let bundleCode = '';
34
35
  let bundleFileId;
@@ -55,8 +56,8 @@ class PackageLoader {
55
56
  console.warn(`Package ${pkg.name} does not have a bundle file defined.`);
56
57
  }
57
58
  // Fallback: try loading from local path if stored bundle is not available
58
- if (!bundleCode && pkg.localPath) {
59
- bundleCode = this._readLocalBundle(pkg) ?? '';
59
+ if (!bundleCode && localPath) {
60
+ bundleCode = this._readLocalBundle(localPath) ?? '';
60
61
  }
61
62
  if (!bundleCode)
62
63
  return;
@@ -64,10 +65,10 @@ class PackageLoader {
64
65
  }
65
66
  catch (err) {
66
67
  // If stored bundle failed to evaluate, try local path as fallback
67
- if (pkg.localPath) {
68
+ if (localPath) {
68
69
  console.warn(`[PackageLoader] Stored bundle failed for ${pkg.name}, trying local path fallback`, err.message);
69
70
  try {
70
- const localBundleCode = this._readLocalBundle(pkg);
71
+ const localBundleCode = this._readLocalBundle(localPath);
71
72
  if (localBundleCode) {
72
73
  return this._evaluateBundle(pkg, localBundleCode);
73
74
  }
@@ -80,14 +81,14 @@ class PackageLoader {
80
81
  return;
81
82
  }
82
83
  }
83
- _readLocalBundle(pkg) {
84
+ _readLocalBundle(localPath) {
84
85
  try {
85
86
  const _require = this.require ?? defaultRequire ?? (typeof require === 'function' ? require : null);
86
- if (!_require || !pkg.localPath)
87
+ if (!_require || !localPath)
87
88
  return;
88
89
  const fs = _require('fs');
89
90
  const path = _require('path');
90
- return fs.readFileSync(path.join(pkg.localPath, 'dist', 'package.bundle.js'), 'utf8');
91
+ return fs.readFileSync(path.join(localPath, 'dist', 'package.bundle.js'), 'utf8');
91
92
  }
92
93
  catch {
93
94
  return;
@@ -96,9 +96,11 @@ export declare const rpcServerCalls: {
96
96
  }>);
97
97
  voiceGetState: (() => Promise<{
98
98
  state: "disabled" | "idle" | "listening" | "recording" | "processing" | "speaking";
99
+ keyError?: "refused" | "invalid" | "limit" | "throttled";
99
100
  }>);
100
101
  voiceStartRecording: (() => Promise<void>);
101
102
  voiceStopRecording: (() => Promise<void>);
103
+ voiceCancelRecording: (() => Promise<void>);
102
104
  voiceSetTargetChannel: ((channelId: string) => Promise<void>);
103
105
  voiceGetAudioDevices: (() => Promise<string[]>);
104
106
  voiceTestTTS: ((text: string) => Promise<void>);
@@ -107,6 +109,8 @@ export declare const rpcServerCalls: {
107
109
  voiceGetThreadId: (() => Promise<string | null>);
108
110
  voiceSetThreadId: ((threadId: string | null) => Promise<void>);
109
111
  voiceNotifyTextActivity: (() => Promise<void>);
112
+ voiceDisable: (() => Promise<void>);
113
+ voiceEnable: (() => Promise<void>);
110
114
  };
111
115
  export declare const rpcClientCalls: {
112
116
  ping: (msg: string) => Promise<string>;
package/dist/rpc-types.js CHANGED
@@ -45,6 +45,7 @@ exports.rpcServerCalls = {
45
45
  voiceGetState: rpcStub('voiceGetState'),
46
46
  voiceStartRecording: rpcStub('voiceStartRecording'),
47
47
  voiceStopRecording: rpcStub('voiceStopRecording'),
48
+ voiceCancelRecording: rpcStub('voiceCancelRecording'),
48
49
  voiceSetTargetChannel: rpcStub('voiceSetTargetChannel'),
49
50
  voiceGetAudioDevices: rpcStub('voiceGetAudioDevices'),
50
51
  voiceTestTTS: rpcStub('voiceTestTTS'),
@@ -53,6 +54,8 @@ exports.rpcServerCalls = {
53
54
  voiceGetThreadId: rpcStub('voiceGetThreadId'),
54
55
  voiceSetThreadId: rpcStub('voiceSetThreadId'),
55
56
  voiceNotifyTextActivity: rpcStub('voiceNotifyTextActivity'),
57
+ voiceDisable: rpcStub('voiceDisable'),
58
+ voiceEnable: rpcStub('voiceEnable'),
56
59
  // TODO try to get rid of this and rely on the client-side table and server-side table individually emitting events
57
60
  // TODO TODO before deleting this, check if we can stop client-side tables from emitting events and rely solely on server-side tables
58
61
  // propagating events with rpcClientCalls.emitEvent. It's very likely we're currently seeing two events for every one write originating from the UI
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-sdk",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/peers-app/peers-sdk.git"