@applica-software-guru/persona-sdk 0.1.100 → 0.1.101

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.
Files changed (170) hide show
  1. package/.eslintrc.cjs +6 -5
  2. package/.nvmrc +1 -1
  3. package/.prettierignore +3 -5
  4. package/.prettierrc +3 -5
  5. package/README.md +360 -20
  6. package/bitbucket-pipelines.yml +6 -5
  7. package/dist/bundle.cjs.js +1 -27
  8. package/dist/bundle.cjs.js.map +1 -1
  9. package/dist/bundle.es.js +700 -5086
  10. package/dist/bundle.es.js.map +1 -1
  11. package/dist/index.d.ts +1442 -8
  12. package/package.json +9 -51
  13. package/src/agents/agents-api.ts +66 -0
  14. package/src/agents/types.ts +349 -0
  15. package/src/auth/api-key-auth.ts +13 -0
  16. package/src/auth/authentication-provider.ts +4 -0
  17. package/src/auth/bearer-token-auth.ts +13 -0
  18. package/src/auth/index.ts +3 -0
  19. package/src/billing/billing-client.ts +182 -0
  20. package/src/billing/types.ts +166 -0
  21. package/src/credentials/credentials-api.ts +40 -0
  22. package/src/credentials/types.ts +67 -0
  23. package/src/exceptions.ts +10 -0
  24. package/src/features/feature-templates-api.ts +43 -0
  25. package/src/features/features-api.ts +16 -0
  26. package/src/features/types.ts +25 -0
  27. package/src/http-api.ts +102 -0
  28. package/src/index.ts +179 -7
  29. package/src/knowledges/knowledge-base-documents-api.ts +39 -0
  30. package/src/knowledges/knowledge-bases-api.ts +48 -0
  31. package/src/knowledges/types.ts +70 -0
  32. package/src/known-models/known-models-api.ts +33 -0
  33. package/src/known-models/types.ts +7 -0
  34. package/src/missions/missions-api.ts +62 -0
  35. package/src/missions/types.ts +25 -0
  36. package/src/paginated.ts +6 -0
  37. package/src/persona-sdk.ts +104 -0
  38. package/src/projects/projects-api.ts +90 -0
  39. package/src/projects/types.ts +52 -0
  40. package/src/revisions/types.ts +9 -0
  41. package/src/service-prices/service-prices-api.ts +33 -0
  42. package/src/service-prices/types.ts +8 -0
  43. package/src/sessions/sessions-api.ts +90 -0
  44. package/src/sessions/types.ts +150 -0
  45. package/src/triggers/trigger-executions-api.ts +28 -0
  46. package/src/triggers/triggers-api.ts +38 -0
  47. package/src/triggers/types.ts +50 -0
  48. package/src/values/values-api.ts +84 -0
  49. package/src/workflows/types.ts +150 -0
  50. package/src/workflows/workflow-executions-api.ts +28 -0
  51. package/src/workflows/workflows-api.ts +52 -0
  52. package/tsconfig.json +20 -28
  53. package/vite.config.ts +20 -67
  54. package/.github/copilot-instructions.md +0 -3
  55. package/CLAUDE.md +0 -3
  56. package/GEMINI.md +0 -3
  57. package/components.json +0 -24
  58. package/dist/bundle.iife.js +0 -28
  59. package/dist/bundle.iife.js.map +0 -1
  60. package/dist/bundle.umd.js +0 -28
  61. package/dist/bundle.umd.js.map +0 -1
  62. package/dist/index.d.ts.map +0 -1
  63. package/dist/logging.d.ts +0 -18
  64. package/dist/logging.d.ts.map +0 -1
  65. package/dist/messages.d.ts +0 -9
  66. package/dist/messages.d.ts.map +0 -1
  67. package/dist/projects.d.ts +0 -17
  68. package/dist/projects.d.ts.map +0 -1
  69. package/dist/protocol/base.d.ts +0 -25
  70. package/dist/protocol/base.d.ts.map +0 -1
  71. package/dist/protocol/index.d.ts +0 -6
  72. package/dist/protocol/index.d.ts.map +0 -1
  73. package/dist/protocol/rest.d.ts +0 -25
  74. package/dist/protocol/rest.d.ts.map +0 -1
  75. package/dist/protocol/transaction.d.ts +0 -56
  76. package/dist/protocol/transaction.d.ts.map +0 -1
  77. package/dist/protocol/webrtc.d.ts +0 -60
  78. package/dist/protocol/webrtc.d.ts.map +0 -1
  79. package/dist/protocol/websocket.d.ts +0 -22
  80. package/dist/protocol/websocket.d.ts.map +0 -1
  81. package/dist/runtime/context.d.ts +0 -34
  82. package/dist/runtime/context.d.ts.map +0 -1
  83. package/dist/runtime/file-attachment-adapter.d.ts +0 -15
  84. package/dist/runtime/file-attachment-adapter.d.ts.map +0 -1
  85. package/dist/runtime/handlers.d.ts +0 -21
  86. package/dist/runtime/handlers.d.ts.map +0 -1
  87. package/dist/runtime/listeners.d.ts +0 -6
  88. package/dist/runtime/listeners.d.ts.map +0 -1
  89. package/dist/runtime/protocols.d.ts +0 -17
  90. package/dist/runtime/protocols.d.ts.map +0 -1
  91. package/dist/runtime/threads.d.ts +0 -34
  92. package/dist/runtime/threads.d.ts.map +0 -1
  93. package/dist/runtime/utils.d.ts +0 -10
  94. package/dist/runtime/utils.d.ts.map +0 -1
  95. package/dist/runtime.d.ts +0 -6
  96. package/dist/runtime.d.ts.map +0 -1
  97. package/dist/storage/base.d.ts +0 -9
  98. package/dist/storage/base.d.ts.map +0 -1
  99. package/dist/storage/index.d.ts +0 -3
  100. package/dist/storage/index.d.ts.map +0 -1
  101. package/dist/storage/persona.d.ts +0 -29
  102. package/dist/storage/persona.d.ts.map +0 -1
  103. package/dist/tools.d.ts +0 -72
  104. package/dist/tools.d.ts.map +0 -1
  105. package/dist/types.d.ts +0 -237
  106. package/dist/types.d.ts.map +0 -1
  107. package/docs/README.md +0 -13
  108. package/docs/api-reference.md +0 -16
  109. package/docs/contributing.md +0 -21
  110. package/docs/customization.md +0 -74
  111. package/docs/features.md +0 -7
  112. package/docs/installation.md +0 -9
  113. package/docs/messages.md +0 -214
  114. package/docs/protocols.md +0 -39
  115. package/docs/transactions.md +0 -121
  116. package/docs/usage.md +0 -40
  117. package/jsconfig.node.json +0 -10
  118. package/playground/index.html +0 -14
  119. package/playground/src/app.tsx +0 -10
  120. package/playground/src/chat.tsx +0 -117
  121. package/playground/src/components/assistant-ui/assistant-modal.tsx +0 -57
  122. package/playground/src/components/assistant-ui/attachment.tsx +0 -197
  123. package/playground/src/components/assistant-ui/markdown-text.tsx +0 -228
  124. package/playground/src/components/assistant-ui/thread-list.tsx +0 -91
  125. package/playground/src/components/assistant-ui/thread.tsx +0 -302
  126. package/playground/src/components/assistant-ui/threadlist-sidebar.tsx +0 -59
  127. package/playground/src/components/assistant-ui/tool-fallback.tsx +0 -93
  128. package/playground/src/components/assistant-ui/tooltip-icon-button.tsx +0 -42
  129. package/playground/src/components/chat/logging.tsx +0 -53
  130. package/playground/src/components/ui/avatar.tsx +0 -51
  131. package/playground/src/components/ui/button.tsx +0 -60
  132. package/playground/src/components/ui/dialog.tsx +0 -141
  133. package/playground/src/components/ui/input.tsx +0 -21
  134. package/playground/src/components/ui/separator.tsx +0 -26
  135. package/playground/src/components/ui/sheet.tsx +0 -139
  136. package/playground/src/components/ui/sidebar.tsx +0 -619
  137. package/playground/src/components/ui/skeleton.tsx +0 -13
  138. package/playground/src/components/ui/tooltip.tsx +0 -59
  139. package/playground/src/hooks/theme.ts +0 -70
  140. package/playground/src/hooks/use-mobile.ts +0 -19
  141. package/playground/src/lib/utils.ts +0 -6
  142. package/playground/src/main.tsx +0 -10
  143. package/playground/src/styles.css +0 -120
  144. package/playground/src/tools.ts +0 -149
  145. package/playground/src/vite-env.d.ts +0 -1
  146. package/preview-build.sh +0 -23
  147. package/src/logging.ts +0 -34
  148. package/src/messages.ts +0 -202
  149. package/src/projects.ts +0 -57
  150. package/src/protocol/base.ts +0 -73
  151. package/src/protocol/index.ts +0 -5
  152. package/src/protocol/rest.ts +0 -107
  153. package/src/protocol/transaction.ts +0 -182
  154. package/src/protocol/webrtc.ts +0 -379
  155. package/src/protocol/websocket.ts +0 -111
  156. package/src/runtime/context.ts +0 -88
  157. package/src/runtime/file-attachment-adapter.ts +0 -48
  158. package/src/runtime/handlers.ts +0 -322
  159. package/src/runtime/index.ts +0 -6
  160. package/src/runtime/listeners.ts +0 -79
  161. package/src/runtime/protocols.ts +0 -169
  162. package/src/runtime/threads.ts +0 -105
  163. package/src/runtime/utils.ts +0 -46
  164. package/src/runtime.tsx +0 -334
  165. package/src/storage/base.ts +0 -13
  166. package/src/storage/index.ts +0 -2
  167. package/src/storage/persona.ts +0 -138
  168. package/src/tools.ts +0 -211
  169. package/src/types.ts +0 -284
  170. package/tsconfig.node.json +0 -15
@@ -1,73 +0,0 @@
1
- import {
2
- MessageListenerCallback,
3
- PersonaAgentContext,
4
- PersonaPacket,
5
- PersonaProtocol,
6
- PersonaTransaction,
7
- ProtocolStatus,
8
- Session,
9
- StatusChangeCallback,
10
- } from '../types';
11
-
12
- abstract class PersonaProtocolBase implements PersonaProtocol {
13
- abstract status: ProtocolStatus;
14
- abstract session: Session;
15
- abstract autostart: boolean;
16
-
17
- private statusChangeCallbacks: StatusChangeCallback[] = [];
18
- private messageCallbacks: MessageListenerCallback[] = [];
19
-
20
- public addStatusChangeListener(callback: StatusChangeCallback) {
21
- this.statusChangeCallbacks.push(callback);
22
- }
23
-
24
- public addPacketListener(callback: MessageListenerCallback) {
25
- this.messageCallbacks.push(callback);
26
- }
27
- public async syncSession(session: Session): Promise<void> {
28
- this.session = session;
29
- }
30
-
31
- public async notifyPacket(message: PersonaPacket): Promise<void> {
32
- this.messageCallbacks.forEach((callback) => callback(message));
33
- }
34
- public async notifyPackets(messages: PersonaPacket[]): Promise<void> {
35
- messages.forEach((message) => {
36
- this.messageCallbacks.forEach((callback) => callback(message));
37
- });
38
- }
39
-
40
- public async setSession(session: Session): Promise<void> {
41
- this.session = session;
42
- }
43
- public async setStatus(status: ProtocolStatus): Promise<void> {
44
- const notify = this.status !== status;
45
- this.status = status;
46
- if (!notify) {
47
- return;
48
- }
49
- this.statusChangeCallbacks.forEach((callback) => callback(status));
50
- }
51
-
52
- public clearListeners(): void {
53
- this.statusChangeCallbacks = [];
54
- this.messageCallbacks = [];
55
- }
56
-
57
- public setAgentContext(context: PersonaAgentContext): Promise<void> {
58
- return this.sendPacket({
59
- type: 'command',
60
- payload: { command: 'set_initial_context', arguments: context },
61
- });
62
- }
63
-
64
- abstract getName(): string;
65
- abstract getPriority(): number;
66
- abstract connect(session?: Session): Promise<Session>;
67
- abstract disconnect(): Promise<void>;
68
- abstract sendPacket(packet: PersonaPacket): Promise<void>;
69
-
70
- public onTransaction(_: PersonaTransaction) {}
71
- }
72
-
73
- export { PersonaProtocolBase };
@@ -1,5 +0,0 @@
1
- export * from './rest';
2
- export * from './base';
3
- export * from './websocket';
4
- export * from './webrtc';
5
- export * from './transaction';
@@ -1,107 +0,0 @@
1
- import { PersonaProtocolBase } from './base';
2
- import {
3
- PersonaResponse,
4
- Session,
5
- ProtocolStatus,
6
- PersonaProtocolBaseConfig,
7
- PersonaMessage,
8
- PersonaPacket,
9
- PersonaCommand,
10
- } from '../types';
11
- import { ToolInstance } from '../tools';
12
-
13
- type PersonaRESTProtocolConfig = PersonaProtocolBaseConfig & {
14
- apiUrl: string;
15
- };
16
-
17
- class PersonaRESTProtocol extends PersonaProtocolBase {
18
- status: ProtocolStatus;
19
- autostart: boolean;
20
- session: Session;
21
- config: PersonaRESTProtocolConfig;
22
- notify: boolean = true;
23
- context: Record<string, any> = {};
24
- tools: ToolInstance[] = [];
25
-
26
- constructor(config: PersonaRESTProtocolConfig) {
27
- super();
28
- this.config = config;
29
- this.status = 'disconnected';
30
- this.autostart = true;
31
- }
32
-
33
- public getName(): string {
34
- return 'rest';
35
- }
36
-
37
- public getPriority(): number {
38
- return 100;
39
- }
40
-
41
- public async connect(session: Session): Promise<Session> {
42
- this.setStatus('connected');
43
- return session;
44
- }
45
-
46
- public async disconnect(): Promise<void> {
47
- this.setStatus('disconnected');
48
- this.session = null;
49
- }
50
-
51
- public async syncSession(session: Session): Promise<void> {
52
- this.session = session;
53
- }
54
-
55
- public async sendPacket(packet: PersonaPacket): Promise<void> {
56
- const { apiUrl, apiKey, agentId } = this.config;
57
- const sessionId = this.session ?? 'new';
58
- if (packet.type === 'command' && (packet?.payload as PersonaCommand)?.command == 'set_initial_context') {
59
- this.context = (packet?.payload as PersonaCommand)?.arguments;
60
- return;
61
- } else if (packet.type === 'command' && (packet?.payload as PersonaCommand)?.command == 'set_local_tools') {
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
- }
73
- return;
74
- }
75
- const input = packet.payload as PersonaMessage;
76
- try {
77
- const response = await fetch(`${apiUrl}/sessions/${sessionId}/messages`, {
78
- body: JSON.stringify({ agentId, userMessage: input, initialContext: this.context, tools: this.tools }),
79
- method: 'POST',
80
- headers: {
81
- 'Content-Type': 'application/json',
82
- 'x-persona-apikey': apiKey,
83
- },
84
- });
85
- const personaResponse = (await response.json()) as PersonaResponse;
86
- this.notifyPackets(
87
- personaResponse.response.messages.map((payload) => ({
88
- type: 'message',
89
- payload,
90
- })),
91
- );
92
- } catch (error) {
93
- this.notifyPacket({
94
- type: 'message',
95
- payload: {
96
- role: 'assistant',
97
- type: 'text',
98
- text: 'An error occurred while processing your request. Please try again later.',
99
- },
100
- });
101
- this.config.logger?.error('Error sending packet:', error);
102
- }
103
- }
104
- }
105
-
106
- export { PersonaRESTProtocol };
107
- export type { PersonaRESTProtocolConfig };
@@ -1,182 +0,0 @@
1
- import { PersonaProtocolBase } from './base';
2
- import { Session, ProtocolStatus, PersonaProtocolBaseConfig, PersonaTransaction, FunctionCall, PersonaPacket } from '../types';
3
- import { ToolInstance } from '../tools';
4
- import _ from 'lodash';
5
-
6
- type FinishTransactionRequest = {
7
- success: boolean;
8
- output: any;
9
- error: string | null;
10
- };
11
-
12
- class PersonaTransactionsManager {
13
- private config: PersonaTransactionProtocolConfig;
14
-
15
- constructor(config: PersonaTransactionProtocolConfig) {
16
- this.config = config;
17
- }
18
-
19
- async complete(transaction: PersonaTransaction, request: FinishTransactionRequest): Promise<void> {
20
- await this.persist(transaction, { ...request, success: true });
21
- this.config.logger?.debug('Transaction completed:', transaction);
22
- }
23
-
24
- async fail(transaction: PersonaTransaction, request: FinishTransactionRequest): Promise<void> {
25
- await this.persist(transaction, { ...request, success: false });
26
- this.config.logger?.debug('Transaction failed:', { ...transaction, ...request });
27
- }
28
-
29
- async persist(transaction: PersonaTransaction, request: FinishTransactionRequest): Promise<void> {
30
- await fetch(`${this.config.apiUrl}/transactions/${transaction.id}`, {
31
- body: JSON.stringify(request),
32
- method: 'POST',
33
- headers: {
34
- 'Content-Type': 'application/json',
35
- Accept: 'application/json',
36
- 'x-persona-apikey': this.config.apiKey,
37
- },
38
- });
39
- }
40
- }
41
-
42
- export type PersonaToolCallback = (...args: any[]) => void | Record<string, any> | Promise<void | Record<string, any>>;
43
- export type PersonaTools = {
44
- [key: string]: PersonaToolCallback;
45
- };
46
-
47
- class PersonaPersistableTransaction {
48
- private transaction: PersonaTransaction;
49
- private manager: PersonaTransactionsManager;
50
-
51
- constructor(transaction: PersonaTransaction, manager: PersonaTransactionsManager) {
52
- this.transaction = transaction;
53
- this.manager = manager;
54
- }
55
-
56
- public getFunctionCall(): FunctionCall | null {
57
- return this.transaction.functionCall;
58
- }
59
-
60
- async invoke(tools: PersonaTools, toolInstance?: ToolInstance): Promise<void> {
61
- const functionCall = this.transaction.functionCall;
62
- if (!functionCall) {
63
- await this.fail('No function call found');
64
- return;
65
- }
66
- const functionName = functionCall.name;
67
- const functionArgs = functionCall.args;
68
- const tool = tools[functionName];
69
- if (!tool) {
70
- await this.fail(`Tool ${functionName} not found`);
71
- return;
72
- }
73
- try {
74
- const properties = _.get(toolInstance, 'schema.config.parameters.properties', {});
75
- const paramNames =
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
-
86
- // Map arguments in order
87
- const orderedArgs = paramNames.map((name: string) => functionArgs[name]);
88
- const result = await tool.apply(null, orderedArgs);
89
- await this.complete(result);
90
- } catch (error) {
91
- await this.fail(`Error executing tool ${functionName}: ${error}`);
92
- }
93
- }
94
- async complete(output: any): Promise<void> {
95
- await this.manager.complete(this.transaction, { success: true, output, error: null });
96
- }
97
- async fail(error: string): Promise<void> {
98
- await this.manager.fail(this.transaction, { success: false, output: null, error });
99
- }
100
- }
101
-
102
- type PersonaTransactionCallback = (transaction: PersonaPersistableTransaction) => void;
103
-
104
- type PersonaTransactionProtocolConfig = PersonaProtocolBaseConfig & {
105
- apiUrl: string;
106
- tools: PersonaTools | ToolInstance[];
107
- onTransaction?: PersonaTransactionCallback;
108
- };
109
-
110
- class PersonaTransactionProtocol extends PersonaProtocolBase {
111
- status: ProtocolStatus;
112
- autostart: boolean;
113
- session: Session;
114
- config: PersonaTransactionProtocolConfig;
115
- notify: boolean = true;
116
- private _tools: PersonaTools;
117
- private _toolSchema: { [key: string]: ToolInstance } = {};
118
-
119
- constructor(config: PersonaTransactionProtocolConfig) {
120
- super();
121
- this.config = config;
122
- this.status = 'disconnected';
123
- this.autostart = true;
124
- if (Array.isArray(config.tools)) {
125
- this._tools = {};
126
- for (const tool of config.tools as ToolInstance[]) {
127
- if (tool.schema && tool.implementation) {
128
- this._tools[tool.schema.name] = tool.implementation;
129
- this._toolSchema[tool.schema.name] = tool;
130
- }
131
- }
132
- } else {
133
- this._tools = config.tools as PersonaTools;
134
- }
135
- }
136
-
137
- public getName(): string {
138
- return 'transaction';
139
- }
140
-
141
- public getPriority(): number {
142
- return 0;
143
- }
144
-
145
- public getToolInstance(name: string): ToolInstance | undefined {
146
- return this._toolSchema[name];
147
- }
148
-
149
- public async connect(session: Session): Promise<Session> {
150
- this.setStatus('connected');
151
- return session;
152
- }
153
-
154
- public async disconnect(): Promise<void> {
155
- this.setStatus('disconnected');
156
- this.session = null;
157
- }
158
-
159
- public async syncSession(session: Session): Promise<void> {
160
- this.session = session;
161
- }
162
-
163
- public async sendPacket(_: PersonaPacket): Promise<void> {}
164
-
165
- public onTransaction(transaction: PersonaTransaction): void {
166
- const manager = new PersonaTransactionsManager(this.config);
167
- const persistable = new PersonaPersistableTransaction(transaction, manager);
168
- if (this.config.onTransaction) {
169
- this.config.onTransaction(persistable);
170
- } else {
171
- const toolInstance = transaction.functionCall ? this.getToolInstance(transaction.functionCall.name) : undefined;
172
- persistable.invoke(this._tools, toolInstance);
173
- }
174
- }
175
-
176
- public getTools(): PersonaTools {
177
- return this._tools;
178
- }
179
- }
180
-
181
- export { PersonaTransactionProtocol };
182
- export type { PersonaTransactionProtocolConfig, FinishTransactionRequest, PersonaPersistableTransaction, PersonaTransactionCallback };