psadk 1.1.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +21 -0
  3. package/README.md +205 -0
  4. package/build/main/index.d.ts +6 -0
  5. package/build/main/index.js +23 -0
  6. package/build/main/lib/ILogger.d.ts +9 -0
  7. package/build/main/lib/ILogger.js +25 -0
  8. package/build/main/lib/PSAI.d.ts +29 -0
  9. package/build/main/lib/PSAI.js +383 -0
  10. package/build/main/lib/PSAgent.d.ts +215 -0
  11. package/build/main/lib/PSAgent.js +990 -0
  12. package/build/main/lib/PSAgentConfig.d.ts +23 -0
  13. package/build/main/lib/PSAgentConfig.js +3 -0
  14. package/build/main/lib/PSAgentLogger.d.ts +13 -0
  15. package/build/main/lib/PSAgentLogger.js +33 -0
  16. package/build/main/lib/PSAgentTask.d.ts +12 -0
  17. package/build/main/lib/PSAgentTask.js +30 -0
  18. package/build/main/lib/PSAgentTool.d.ts +56 -0
  19. package/build/main/lib/PSAgentTool.js +84 -0
  20. package/build/main/lib/ai.d.ts +11 -0
  21. package/build/main/lib/ai.js +127 -0
  22. package/build/main/lib/async.d.ts +20 -0
  23. package/build/main/lib/async.js +36 -0
  24. package/build/main/lib/getServiceToken.d.ts +1 -0
  25. package/build/main/lib/getServiceToken.js +3 -0
  26. package/build/main/lib/jwt.d.ts +41 -0
  27. package/build/main/lib/jwt.js +73 -0
  28. package/build/main/lib/number.d.ts +43 -0
  29. package/build/main/lib/number.js +56 -0
  30. package/build/main/lib/tools/PSAentTool.d.ts +7 -0
  31. package/build/main/lib/tools/PSAentTool.js +78 -0
  32. package/build/main/lib/tools/PSArtifactTool copy.d.ts +7 -0
  33. package/build/main/lib/tools/PSArtifactTool copy.js +78 -0
  34. package/build/main/lib/tools/PSArtifactTool.d.ts +7 -0
  35. package/build/main/lib/tools/PSArtifactTool.js +79 -0
  36. package/build/main/lib/tools/PSSubAgentTool.d.ts +20 -0
  37. package/build/main/lib/tools/PSSubAgentTool.js +163 -0
  38. package/build/module/index.d.ts +6 -0
  39. package/build/module/index.js +7 -0
  40. package/build/module/lib/PSAI.d.ts +25 -0
  41. package/build/module/lib/PSAI.js +314 -0
  42. package/build/module/lib/PSAgent.d.ts +215 -0
  43. package/build/module/lib/PSAgent.js +992 -0
  44. package/build/module/lib/async.d.ts +20 -0
  45. package/build/module/lib/async.js +32 -0
  46. package/build/module/lib/number.d.ts +43 -0
  47. package/build/module/lib/number.js +51 -0
  48. package/package.json +122 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## 1.1.0 (2025-09-17)
4
+
5
+ ### Features
6
+
7
+ - add @modelcontextprotocol/sdk dependency and enhance PSAI class with LLM proxy functionality ([c8cf308](https://pscode.lioncloud.net///commit/c8cf308c1420ffc25cde720df11270e08c253c58))
8
+
9
+ ### Bug Fixes
10
+
11
+ - update samples link in README.md ([93815a9](https://pscode.lioncloud.net///commit/93815a9a77d595298d363ef31707cdf76a2fd7d2))
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Rakesh Ravuri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,205 @@
1
+ # PSADK
2
+
3
+ ps adk adapter
4
+
5
+ - [samples](https://pscode.lioncloud.net/agents/psadk_samples) : sample agents using PSADK
6
+
7
+ ## Documentation
8
+
9
+ The classes are documented here [Documentation](./globals.md)
10
+
11
+ ## Developing with PSADK
12
+
13
+ ### A2A Server
14
+
15
+ #### hello agent - simple chat agent
16
+
17
+ clone of https://github.com/a2aproject/a2a-samples/blob/main/samples/js/src/agents/coder/index.ts
18
+
19
+ ```typescript
20
+ import { getServiceToken, PSAgent, PSAgentLogger } from 'psadk';
21
+ import dotenv from 'dotenv';
22
+
23
+ dotenv.config();
24
+
25
+ async function main() {
26
+ const token = await getServiceToken({});
27
+ const HelloAgent = new PSAgent({
28
+ name: 'HelloAgent',
29
+ description: 'A simple hello world agent',
30
+ instruction: 'You are a friendly assistant that greets users.',
31
+ token,
32
+ port: 41241,
33
+ log: new PSAgentLogger({ prefix: 'HelloAgent' }),
34
+ });
35
+ const { app } = HelloAgent.getA2AServer();
36
+ app.listen(41241, () => {
37
+ console.log('HelloAgent is running on http://localhost:41241');
38
+ });
39
+ }
40
+
41
+ main().catch((error) => {
42
+ console.error(error);
43
+ process.exit(1);
44
+ });
45
+ ```
46
+
47
+ create a .env file with the appropriate keys
48
+
49
+ ```bash
50
+ PS_API_URL=https://dev.lionis.ai
51
+ PS_APP_KEY=sk_0abb4....
52
+
53
+ PS_CLIENT_ID=b5cc89b7-....
54
+ PS_PROJECT_ID=15a2e....
55
+ PS_WORKSPACE_ID=4ffba209-xxx-xxx-xxx-....
56
+
57
+ PS_SVC_CLIENT_ID=0483....
58
+ PS_SVC_CLIENT_SECRET=gfjt678...
59
+ PS_SVC_APP_KEY=sk_5f2967....
60
+ DEBUG=*
61
+
62
+ ```
63
+
64
+ #### movie info agent - example with custom tools
65
+
66
+ clone of https://github.com/a2aproject/a2a-samples/blob/main/samples/js/src/agents/movie-agent/index.ts
67
+
68
+ ```typescript
69
+ import { PSAI, PSAgent, PSAgentLogger } from 'psadk';
70
+ import dotenv from 'dotenv';
71
+ import { movie_search_tool, movie_searchpeople_tool } from './tmdb_tools.js';
72
+ import { prompt } from './movie_agent_prompts.js';
73
+ dotenv.config();
74
+
75
+ async function main() {
76
+ // const token = await PSAI.getServiceToken({});
77
+ const token = (await PSAI.getAuthToken()).accessToken;
78
+ const instruction = prompt.replace('{{now}}', new Date().toLocaleString());
79
+ const MovieAgent = new PSAgent({
80
+ name: 'MovieAgent',
81
+ description: 'An agent that can answer questions about movies using TMDB.',
82
+ instruction,
83
+ model: 'gpt-4.1-mini',
84
+ token,
85
+ port: 41241,
86
+ log: new PSAgentLogger({ prefix: 'MovieAgent' }),
87
+ tools: [movie_search_tool, movie_searchpeople_tool],
88
+ });
89
+ const { app, port } = MovieAgent.getA2AServer();
90
+ app.listen(port, () => {
91
+ console.log(`MovieAgent is running on http://localhost:${port}`);
92
+ });
93
+ }
94
+
95
+ main().catch((error) => {
96
+ console.error(error);
97
+ process.exit(1);
98
+ });
99
+ ```
100
+
101
+ Use can use [a2a inspector ui](https://a2a-inspector-908687846511.us-central1.run.app/)
102
+ just enter the agent card url http://localhost:41241/.well-known/agent-card.json to interact with the agent
103
+
104
+ #### Custom tool
105
+
106
+ ```typescript
107
+ import { PSAgentTool } from 'psadk';
108
+ import { z } from 'zod/v4';
109
+
110
+ export const movie_search_tool = new PSAgentTool({
111
+ name: 'search_movies',
112
+ description: 'search TMDB for movies by title',
113
+ type: 'API',
114
+ local_execution: true,
115
+ hitl: true,
116
+ inputschema: {
117
+ title: `search_movies_inputs.`,
118
+ description: 'Inputs for search_movies tool.',
119
+ url: 'http://localhost/search_movies',
120
+ method: 'POST',
121
+ requestBody: z.toJSONSchema(
122
+ z
123
+ .object({
124
+ query: z.string().meta({
125
+ title: 'query',
126
+ description: 'The search query string for movies.',
127
+ }),
128
+ })
129
+ .meta({
130
+ title: 'search_movies_request_body',
131
+ description:
132
+ 'The request body parameters for the search_movies tool.',
133
+ }),
134
+ { io: 'input' },
135
+ ),
136
+ },
137
+ runCallback: async ({ query }) => {
138
+ console.log('[tmdb:searchMovies]', JSON.stringify(query));
139
+ try {
140
+ const data = await callTmdbApi('movie', query);
141
+
142
+ // Only modify image paths to be full URLs
143
+ const results = data.results.map((movie: any) => {
144
+ if (movie.poster_path) {
145
+ movie.poster_path = `https://image.tmdb.org/t/p/w500${movie.poster_path}`;
146
+ }
147
+ if (movie.backdrop_path) {
148
+ movie.backdrop_path = `https://image.tmdb.org/t/p/w500${movie.backdrop_path}`;
149
+ }
150
+ return movie;
151
+ });
152
+
153
+ return {
154
+ status: 'success',
155
+ output: {
156
+ ...data,
157
+ results,
158
+ },
159
+ };
160
+ } catch (error) {
161
+ console.error('Error searching movies:', error);
162
+ // Re-throwing allows the caller to handle it appropriately
163
+ throw error;
164
+ }
165
+ },
166
+ });
167
+ ```
168
+
169
+ ### Client: Sending a Message
170
+
171
+ The A2AClient makes it easy to communicate with any A2A-compliant agent.
172
+
173
+ ```typescript
174
+ // client.ts
175
+ import { A2AClient, SendMessageSuccessResponse } from '@a2a-js/sdk/client';
176
+ import { Message, MessageSendParams } from '@a2a-js/sdk';
177
+ import { v4 as uuidv4 } from 'uuid';
178
+
179
+ async function run() {
180
+ // Create a client pointing to the agent's Agent Card URL.
181
+ const client = await A2AClient.fromCardUrl(
182
+ 'http://localhost:41241/.well-known/agent-card.json',
183
+ );
184
+
185
+ const sendParams: MessageSendParams = {
186
+ message: {
187
+ messageId: uuidv4(),
188
+ role: 'user',
189
+ parts: [{ kind: 'text', text: 'Hi there!' }],
190
+ kind: 'message',
191
+ },
192
+ };
193
+
194
+ const response = await client.sendMessage(sendParams);
195
+
196
+ if ('error' in response) {
197
+ console.error('Error:', response.error.message);
198
+ } else {
199
+ const result = (response as SendMessageSuccessResponse).result as Message;
200
+ console.log('Agent response:', result.parts[0].text); // "Hello, world!"
201
+ }
202
+ }
203
+
204
+ await run();
205
+ ```
@@ -0,0 +1,6 @@
1
+ export * from './lib/PSAI';
2
+ export * from './lib/PSAgent';
3
+ export * from './lib/PSAgentConfig';
4
+ export * from './lib/PSAgentLogger';
5
+ export * from './lib/PSAgentTool';
6
+ export * from './lib/PSAgentTask';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./lib/PSAI"), exports);
18
+ __exportStar(require("./lib/PSAgent"), exports);
19
+ __exportStar(require("./lib/PSAgentConfig"), exports);
20
+ __exportStar(require("./lib/PSAgentLogger"), exports);
21
+ __exportStar(require("./lib/PSAgentTool"), exports);
22
+ __exportStar(require("./lib/PSAgentTask"), exports);
23
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDZDQUEyQjtBQUMzQixnREFBOEI7QUFDOUIsc0RBQW9DO0FBQ3BDLHNEQUFvQztBQUNwQyxvREFBa0M7QUFDbEMsb0RBQWtDIn0=
@@ -0,0 +1,9 @@
1
+ export type AgentLoggerType = 'debug' | 'info' | 'error' | 'warn' | 'done';
2
+ export default class PSAgentLogger {
3
+ log(type: string, message: any, ...optionalParams: any[]): void;
4
+ debug(message: string, ...optionalParams: any[]): void;
5
+ info(message: string, ...optionalParams: any[]): void;
6
+ error(message: string, ...optionalParams: any[]): void;
7
+ warn(message: string, ...optionalParams: any[]): void;
8
+ done(message?: string, ...optionalParams: any[]): void;
9
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ console.log;
4
+ class PSAgentLogger {
5
+ log(type, message, ...optionalParams) {
6
+ console.log(`[${new Date().toISOString()}] [${type.toUpperCase()}] ${message}`, ...optionalParams);
7
+ }
8
+ debug(message, ...optionalParams) {
9
+ this.log('debug', message, ...optionalParams);
10
+ }
11
+ info(message, ...optionalParams) {
12
+ this.log('info', message, ...optionalParams);
13
+ }
14
+ error(message, ...optionalParams) {
15
+ this.log('error', message, ...optionalParams);
16
+ }
17
+ warn(message, ...optionalParams) {
18
+ this.log('warn', message, ...optionalParams);
19
+ }
20
+ done(message = '', ...optionalParams) {
21
+ this.log('done', message, ...optionalParams);
22
+ }
23
+ }
24
+ exports.default = PSAgentLogger;
25
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSUxvZ2dlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9saWIvSUxvZ2dlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUNBLE9BQU8sQ0FBQyxHQUFHLENBQUE7QUFFWCxNQUFxQixhQUFhO0lBQ2hDLEdBQUcsQ0FBQyxJQUFZLEVBQUUsT0FBVyxFQUFFL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declare class PSAI {
3
+ private readonly token;
4
+ private dimensions;
5
+ private readonly baseUrl;
6
+ private readonly log;
7
+ private readonly clientid?;
8
+ constructor(token: string, baseUrl?: string, log?: PSAgentLogger);
9
+ getDimensions(embeddingModel?: string): number;
10
+ embedQuery(text: string, embeddingModel?: string): Promise<number[]>;
11
+ embedDocuments(text: string[], embeddingModel?: string): Promise<number[][]>;
12
+ getModels(): Promise<any>;
13
+ llm(prompt: string, model?: string, systemmsg?: string): Promise<unknown>;
14
+ static getServiceToken(options?: Record<string, string>): Promise<string>;
15
+ /**
16
+ * fetch access token by launching a local server to listen for the callback
17
+ * @param options - baseUrl and appKey for authentication
18
+ * @returns accessToken and refreshToken
19
+ * @throws error if any required values are missing or if authentication fails
20
+ */
21
+ static getAuthToken(options?: Record<string, string>): Promise<{
22
+ accessToken: string;
23
+ refreshToken: string;
24
+ }>;
25
+ static getLLMproxy({ headers, baseapiurl }?: {
26
+ headers?: Record<string, string>;
27
+ baseapiurl?: string;
28
+ }): import("express-serve-static-core").Express;
29
+ }