@applica-software-guru/persona-sdk 0.1.69 → 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.
@@ -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,W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AC;CAC5C,CAAC;AAEF,cAAM,0BAA2B,SAAQ,mBAAmB;IAC1D,MAAM,EAAE,cAAc,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,gCAAgC,CAAC;IACzC,MAAM,EAAE,OAAO,CAAQ;IACvB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,WAAW,CAAuC;gBAE9C,MAAM,EAAE,gCAAgC;IAkB7C,OAAO,IAAI,MAAM;IAIjB,WAAW,IAAI,MAAM;IAIrB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAIjD,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,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAEjD,aAAa,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI;IAWpD,QAAQ,IAAI,YAAY;CAGhC;AAED,OAAO,EAAE,0BAA0B,EAAE,CAAC;AACtC,YAAY,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,6BAA6B,EAAE,0BAA0B,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.69",
4
+ "version": "0.1.70",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -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