@applica-software-guru/persona-sdk 0.1.68 → 0.1.70

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.
@@ -1 +1 @@
1
- {"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../../../src/protocol/rest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAEL,OAAO,EACP,cAAc,EACd,yBAAyB,EAEzB,aAAa,EAEd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,KAAK,yBAAyB,GAAG,yBAAyB,GAAG;IAC3D,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,cAAM,mBAAoB,SAAQ,mBAAmB;IACnD,MAAM,EAAE,cAAc,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,yBAAyB,CAAC;IAClC,MAAM,EAAE,OAAO,CAAQ;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;IAClC,KAAK,EAAE,YAAY,EAAE,CAAM;gBAEf,MAAM,EAAE,yBAAyB;IAOtC,OAAO,IAAI,MAAM;IAIjB,WAAW,IAAI,MAAM;IAIf,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAK3C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CA8C9D;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAC/B,YAAY,EAAE,yBAAyB,EAAE,CAAC"}
1
+ {"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../../../src/protocol/rest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAEL,OAAO,EACP,cAAc,EACd,yBAAyB,EAEzB,aAAa,EAEd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,KAAK,yBAAyB,GAAG,yBAAyB,GAAG;IAC3D,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,cAAM,mBAAoB,SAAQ,mBAAmB;IACnD,MAAM,EAAE,cAAc,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,yBAAyB,CAAC;IAClC,MAAM,EAAE,OAAO,CAAQ;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;IAClC,KAAK,EAAE,YAAY,EAAE,CAAM;gBAEf,MAAM,EAAE,yBAAyB;IAOtC,OAAO,IAAI,MAAM;IAIjB,WAAW,IAAI,MAAM;IAIf,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAK3C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAiD9D;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAC/B,YAAY,EAAE,yBAAyB,EAAE,CAAC"}
@@ -22,7 +22,7 @@ declare class PersonaPersistableTransaction {
22
22
  private manager;
23
23
  constructor(transaction: PersonaTransaction, manager: PersonaTransactionsManager);
24
24
  getFunctionCall(): FunctionCall | null;
25
- invoke(tools: PersonaTools): Promise<void>;
25
+ invoke(tools: PersonaTools, toolInstance?: ToolInstance): Promise<void>;
26
26
  complete(output: any): Promise<void>;
27
27
  fail(error: string): Promise<void>;
28
28
  }
@@ -39,9 +39,11 @@ declare class PersonaTransactionProtocol extends PersonaProtocolBase {
39
39
  config: PersonaTransactionProtocolConfig;
40
40
  notify: boolean;
41
41
  private _tools;
42
+ private _toolSchema;
42
43
  constructor(config: PersonaTransactionProtocolConfig);
43
44
  getName(): string;
44
45
  getPriority(): number;
46
+ getToolInstance(name: string): ToolInstance | undefined;
45
47
  connect(session: Session): Promise<Session>;
46
48
  disconnect(): Promise<void>;
47
49
  syncSession(session: Session): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../src/protocol/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC/H,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,GAAG,CAAC;IACZ,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAAC;AAEF,cAAM,0BAA0B;IAC9B,OAAO,CAAC,MAAM,CAAmC;gBAErC,MAAM,EAAE,gCAAgC;IAI9C,QAAQ,CAAC,WAAW,EAAE,kBAAkB,EAAE,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAK3F,IAAI,CAAC,WAAW,EAAE,kBAAkB,EAAE,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKvF,OAAO,CAAC,WAAW,EAAE,kBAAkB,EAAE,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;CAWjG;AAED,MAAM,MAAM,mBAAmB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,MAAM,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B,GAC1B,CAAC;AACF,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@applica-software-guru/persona-sdk",
3
3
  "private": false,
4
- "version": "0.1.68",
4
+ "version": "0.1.70",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -1,9 +1,14 @@
1
1
  import { Thread } from '@/components/assistant-ui/thread';
2
- import { PersonaRuntimeProvider, PersonaConsoleLogger, Session, usePersonaRuntimeMessages } from '@applica-software-guru/persona-sdk';
2
+ import {
3
+ PersonaRuntimeProvider,
4
+ PersonaConsoleLogger,
5
+ Session,
6
+ usePersonaRuntimeMessages,
7
+ usePersonaRuntimeEndpoint,
8
+ } from '@applica-software-guru/persona-sdk';
3
9
  import { useMemo } from 'react';
4
10
  import _ from 'lodash';
5
11
  import { TooltipProvider } from './components/ui/tooltip';
6
- import { tools } from '@/tools';
7
12
 
8
13
  const logger = new PersonaConsoleLogger();
9
14
 
@@ -21,6 +26,16 @@ function getQueryParam(param: string): string | null {
21
26
  return urlParams.get(param);
22
27
  }
23
28
 
29
+ function EndpointLogger() {
30
+ const endpoint = usePersonaRuntimeEndpoint();
31
+ return (
32
+ <div className="absolute top-0 right-0 w-50 h-40 overflow-y-auto m-2 box-border border-gray-300 rounded-lg shadow-lg p-2">
33
+ <h3 className="text-md font-bold mb-2">Endpoint</h3>
34
+ <p className="top-0 left-0 bg-white text-black text-sm">{endpoint || 'No endpoint available'}</p>
35
+ </div>
36
+ );
37
+ }
38
+
24
39
  function MessageLogger() {
25
40
  const messages = usePersonaRuntimeMessages();
26
41
  const { reasoning, user, assistant, sources } = useMemo(() => {
@@ -81,11 +96,11 @@ function Chat() {
81
96
  userAgent: 'Google Tridroid 14',
82
97
  },
83
98
  }}
84
- tools={tools}
99
+ tools={[]}
85
100
  protocols={{
86
101
  rest: false,
102
+ webrtc: false,
87
103
  websocket: true,
88
- webrtc: true,
89
104
  }}
90
105
  session={session}
91
106
  apiKey={apiKey!}
@@ -97,6 +112,7 @@ function Chat() {
97
112
  </TooltipProvider>
98
113
  </div>
99
114
  <MessageLogger />
115
+ <EndpointLogger />
100
116
  </PersonaRuntimeProvider>
101
117
  );
102
118
  }
@@ -10,6 +10,28 @@
10
10
  import { createTool, PersonaTools } from '@applica-software-guru/persona-sdk';
11
11
 
12
12
  const toolLibrary = [
13
+ createTool({
14
+ name: 'set_field_value',
15
+ title: 'Set Field Value',
16
+ description: 'Sets the value of a specified field in the current form.',
17
+ parameters: {
18
+ name: { type: 'string', description: 'The name of the field to set', required: true },
19
+ value: { type: 'string', description: 'The value to set for the field', required: true },
20
+ },
21
+ output: {
22
+ success: { type: 'boolean', description: 'Indicates if the field value was set successfully' },
23
+ },
24
+ implementation: async (name: string, value: string) => {
25
+ console.log({ name, value });
26
+ const field = document.querySelector(`[name="${name}"]`);
27
+ if (field) {
28
+ (field as HTMLInputElement).value = value;
29
+ return { success: true };
30
+ }
31
+ console.error(`Field with name "${name}" not found.`);
32
+ return { success: false };
33
+ },
34
+ }),
13
35
  createTool({
14
36
  name: 'sum',
15
37
  title: 'Sum two numbers',
@@ -59,14 +59,17 @@ class PersonaRESTProtocol extends PersonaProtocolBase {
59
59
  this.context = (packet?.payload as PersonaCommand)?.arguments;
60
60
  return;
61
61
  } else if (packet.type === 'command' && (packet?.payload as PersonaCommand)?.command == 'set_local_tools') {
62
- this.notifyPacket({
63
- type: 'message',
64
- payload: {
65
- type: 'text',
66
- role: 'assistant',
67
- text: 'Local tools with rest protocol are not supported.',
68
- },
69
- });
62
+ const tools = (packet?.payload as PersonaCommand)?.arguments.tools as ToolInstance[];
63
+ if (tools?.length > 0) {
64
+ this.notifyPacket({
65
+ type: 'message',
66
+ payload: {
67
+ type: 'text',
68
+ role: 'assistant',
69
+ text: 'Local tools with rest protocol are not supported.',
70
+ },
71
+ });
72
+ }
70
73
  return;
71
74
  }
72
75
  const input = packet.payload as PersonaMessage;
@@ -1,6 +1,7 @@
1
1
  import { PersonaProtocolBase } from './base';
2
2
  import { Session, ProtocolStatus, PersonaProtocolBaseConfig, PersonaTransaction, FunctionCall, PersonaPacket } from '../types';
3
3
  import { ToolInstance } from '../tools';
4
+ import _ from 'lodash';
4
5
 
5
6
  type FinishTransactionRequest = {
6
7
  success: boolean;
@@ -56,7 +57,7 @@ class PersonaPersistableTransaction {
56
57
  return this.transaction.functionCall;
57
58
  }
58
59
 
59
- async invoke(tools: PersonaTools): Promise<void> {
60
+ async invoke(tools: PersonaTools, toolInstance?: ToolInstance): Promise<void> {
60
61
  const functionCall = this.transaction.functionCall;
61
62
  if (!functionCall) {
62
63
  await this.fail('No function call found');
@@ -70,15 +71,18 @@ class PersonaPersistableTransaction {
70
71
  return;
71
72
  }
72
73
  try {
73
- // Get parameter names in order
74
+ const properties = _.get(toolInstance, 'schema.config.parameters.properties', {});
74
75
  const paramNames =
75
- tool
76
- .toString()
77
- .replace(/\n/g, ' ')
78
- .match(/^[^(]*\(([^)]*)\)/)?.[1]
79
- .split(',')
80
- .map((p: string) => p.trim())
81
- .filter(Boolean) || [];
76
+ properties && Object.keys(properties).length > 0
77
+ ? Object.keys(properties)
78
+ : tool
79
+ .toString()
80
+ .replace(/\n/g, ' ')
81
+ .match(/^[^(]*\(([^)]*)\)/)?.[1]
82
+ .split(',')
83
+ .map((p: string) => p.trim())
84
+ .filter(Boolean) || [];
85
+
82
86
  // Map arguments in order
83
87
  const orderedArgs = paramNames.map((name: string) => functionArgs[name]);
84
88
  const result = await tool.apply(null, orderedArgs);
@@ -110,6 +114,7 @@ class PersonaTransactionProtocol extends PersonaProtocolBase {
110
114
  config: PersonaTransactionProtocolConfig;
111
115
  notify: boolean = true;
112
116
  private _tools: PersonaTools;
117
+ private _toolSchema: { [key: string]: ToolInstance } = {};
113
118
 
114
119
  constructor(config: PersonaTransactionProtocolConfig) {
115
120
  super();
@@ -121,6 +126,7 @@ class PersonaTransactionProtocol extends PersonaProtocolBase {
121
126
  for (const tool of config.tools as ToolInstance[]) {
122
127
  if (tool.schema && tool.implementation) {
123
128
  this._tools[tool.schema.name] = tool.implementation;
129
+ this._toolSchema[tool.schema.name] = tool;
124
130
  }
125
131
  }
126
132
  } else {
@@ -136,6 +142,10 @@ class PersonaTransactionProtocol extends PersonaProtocolBase {
136
142
  return 0;
137
143
  }
138
144
 
145
+ public getToolInstance(name: string): ToolInstance | undefined {
146
+ return this._toolSchema[name];
147
+ }
148
+
139
149
  public async connect(session: Session): Promise<Session> {
140
150
  this.setStatus('connected');
141
151
  return session;
@@ -153,13 +163,13 @@ class PersonaTransactionProtocol extends PersonaProtocolBase {
153
163
  public async sendPacket(_: PersonaPacket): Promise<void> {}
154
164
 
155
165
  public onTransaction(transaction: PersonaTransaction): void {
156
- console.log('transaction received:', transaction);
157
166
  const manager = new PersonaTransactionsManager(this.config);
158
167
  const persistable = new PersonaPersistableTransaction(transaction, manager);
159
168
  if (this.config.onTransaction) {
160
169
  this.config.onTransaction(persistable);
161
170
  } else {
162
- persistable.invoke(this._tools);
171
+ const toolInstance = transaction.functionCall ? this.getToolInstance(transaction.functionCall.name) : undefined;
172
+ persistable.invoke(this._tools, toolInstance);
163
173
  }
164
174
  }
165
175
 
package/src/runtime.tsx CHANGED
@@ -55,6 +55,27 @@ function fileToBase64(file: File): Promise<string> {
55
55
  });
56
56
  }
57
57
 
58
+ function getFirstAvailableProtocolEndpoint(protocols: PersonaProtocol[]): string | null {
59
+ const extractors: { [key: string]: (protocol: PersonaProtocol) => string } = {
60
+ rest: (protocol) => (protocol as PersonaRESTProtocol).config.apiUrl,
61
+ webrtc: (protocol) =>
62
+ (protocol as PersonaWebRTCProtocol).config.webrtcUrl.replace('/webrtc', '').replace('ws://', 'http://').replace('wss://', 'https://'),
63
+ websocket: (protocol) =>
64
+ (protocol as PersonaWebSocketProtocol).config.webSocketUrl
65
+ .replace('/websocket', '')
66
+ .replace('ws://', 'http://')
67
+ .replace('wss://', 'https://'),
68
+ };
69
+
70
+ for (const protocol of protocols) {
71
+ const extractor = extractors[protocol.getName()];
72
+ if (extractor) {
73
+ return extractor(protocol);
74
+ }
75
+ }
76
+ return null;
77
+ }
78
+
58
79
  function PersonaRuntimeProviderInner({
59
80
  dev = false,
60
81
  baseUrl,
@@ -154,6 +175,7 @@ function PersonaRuntimeProviderInner({
154
175
  'Initializing protocols: ',
155
176
  protocols.map((protocol) => protocol.getName()),
156
177
  );
178
+ const endpoint = getFirstAvailableProtocolEndpoint(protocols);
157
179
  protocols.forEach((protocol) => {
158
180
  protocol.setSession(session);
159
181
  protocol.clearListeners();
@@ -191,12 +213,11 @@ function PersonaRuntimeProviderInner({
191
213
  parseMessages([...currentConversation, ...[{ ...personaMessage, protocol: protocol.getName() }]]),
192
214
  );
193
215
  } else if (message.type === 'reasoning') {
194
- const personaReasoning = message.payload as PersonaReasoning;
216
+ const reasoning = message.payload as PersonaReasoning;
195
217
 
196
- let text = personaReasoning.thought;
197
- if (personaReasoning.imageUrl) {
198
- // add markdown image
199
- text += `\n\n![image](https://persona.applica.guru/api/files/${personaReasoning.imageUrl})`;
218
+ let text = reasoning.thought;
219
+ if (reasoning.imageUrl) {
220
+ text += `\n\n![image](${endpoint}/api/files/${reasoning.imageUrl})`;
200
221
  }
201
222
  const personaMessage: PersonaMessage = { type: 'reasoning', text: text, role: 'assistant', finishReason: 'stop' };
202
223
 
@@ -346,24 +367,7 @@ function usePersonaRuntimeEndpoint(): string | null {
346
367
  throw new Error('usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider');
347
368
  }
348
369
 
349
- const extractors: { [key: string]: (protocol: PersonaProtocol) => string } = {
350
- rest: (protocol) => (protocol as PersonaRESTProtocol).config.apiUrl,
351
- webrtc: (protocol) =>
352
- (protocol as PersonaWebRTCProtocol).config.webrtcUrl.replace('/webrtc', '').replace('ws://', 'http://').replace('wss://', 'https://'),
353
- websocket: (protocol) =>
354
- (protocol as PersonaWebSocketProtocol).config.webSocketUrl
355
- .replace('/websocket', '')
356
- .replace('ws://', 'http://')
357
- .replace('wss://', 'https://'),
358
- };
359
-
360
- for (const protocol of context.protocols) {
361
- const extractor = extractors[protocol.getName()];
362
- if (extractor) {
363
- return extractor(protocol);
364
- }
365
- }
366
- return null;
370
+ return getFirstAvailableProtocolEndpoint(context.protocols);
367
371
  }
368
372
 
369
373
  function usePersonaRuntimeWebRTCProtocol(): PersonaWebRTCProtocol | null {