@digipair/skill-dsp 0.89.0 → 0.91.0-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.
package/.swcrc ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "jsc": {
3
+ "target": "es2017",
4
+ "parser": {
5
+ "syntax": "typescript",
6
+ "decorators": true,
7
+ "dynamicImport": true
8
+ },
9
+ "transform": {
10
+ "decoratorMetadata": true,
11
+ "legacyDecorator": true
12
+ },
13
+ "keepClassNames": true,
14
+ "externalHelpers": true,
15
+ "loose": true
16
+ },
17
+ "module": {
18
+ "type": "es6"
19
+ },
20
+ "sourceMaps": true,
21
+ "exclude": [
22
+ "jest.config.ts",
23
+ ".*\\.spec.tsx?$",
24
+ ".*\\.test.tsx?$",
25
+ "./src/jest-setup.ts$",
26
+ "./**/jest-setup.ts$"
27
+ ]
28
+ }
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # mylib
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build mylib` to build the library.
@@ -0,0 +1,22 @@
1
+ import baseConfig from '../../eslint.config.mjs';
2
+
3
+ export default [
4
+ ...baseConfig,
5
+ {
6
+ files: ['**/*.json'],
7
+ rules: {
8
+ '@nx/dependency-checks': [
9
+ 'error',
10
+ {
11
+ ignoredFiles: [
12
+ '{projectRoot}/eslint.config.{js,cjs,mjs}',
13
+ '{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}',
14
+ ],
15
+ },
16
+ ],
17
+ },
18
+ languageOptions: {
19
+ parser: await import('jsonc-eslint-parser'),
20
+ },
21
+ },
22
+ ];
package/package.json CHANGED
@@ -1,12 +1,28 @@
1
1
  {
2
2
  "name": "@digipair/skill-dsp",
3
- "version": "0.89.0",
3
+ "version": "0.91.0-0",
4
+ "type": "module",
5
+ "main": "dist/libs/skill-dsp/index.cjs.js",
6
+ "module": "dist/libs/skill-dsp/index.esm.js",
7
+ "types": "dist/libs/skill-dsp/index.esm.d.ts",
8
+ "exports": {
9
+ "./package.json": "./libs/skill-dsp/package.json",
10
+ ".": {
11
+ "development": "./dist/libs/skill-dsp/src/index.ts",
12
+ "types": "./dist/libs/skill-dsp/index.esm.d.ts",
13
+ "import": "./dist/libs/skill-dsp/index.esm.js",
14
+ "default": "./dist/libs/skill-dsp/index.cjs.js"
15
+ }
16
+ },
4
17
  "keywords": [
5
18
  "digipair",
6
- "service",
7
- "tool"
19
+ "web",
20
+ "service"
8
21
  ],
9
- "dependencies": {},
10
- "main": "./index.cjs.js",
11
- "module": "./index.esm.js"
12
- }
22
+ "nx": {
23
+ "name": "skill-dsp"
24
+ },
25
+ "dependencies": {
26
+ "@digipair/engine": "0.91.0-0"
27
+ }
28
+ }
@@ -0,0 +1,28 @@
1
+ const { withNx } = require('@nx/rollup/with-nx');
2
+
3
+ module.exports = withNx(
4
+ {
5
+ main: 'libs/skill-dsp/src/index.ts',
6
+ outputPath: 'dist/libs/skill-dsp',
7
+ tsConfig: 'libs/skill-dsp/tsconfig.lib.json',
8
+ compiler: 'swc',
9
+ format: ['esm', "cjs"],
10
+ assets: [
11
+ {
12
+ input: 'libs/skill-dsp/',
13
+ glob: 'package.json',
14
+ output: '.'
15
+ },
16
+ {
17
+ input: 'libs/skill-dsp/src/',
18
+ glob: '*.json',
19
+ output: '.'
20
+ }
21
+ ]
22
+ },
23
+ {
24
+ // Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
25
+ // e.g.
26
+ // output: { sourcemap: true },
27
+ }
28
+ );
@@ -0,0 +1 @@
1
+ declare module 'handlebars/dist/handlebars.min.js';
@@ -0,0 +1,7 @@
1
+ import { skillDsp } from './skill-dsp';
2
+
3
+ describe('skillDsp', () => {
4
+ it('should work', () => {
5
+ expect(skillDsp()).toEqual('skill-dsp');
6
+ });
7
+ });
@@ -0,0 +1,324 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ import { PinsSettings, executePinsList } from '@digipair/engine';
3
+ import {
4
+ AxAI,
5
+ AxAIAzureOpenAI,
6
+ AxAIOllama,
7
+ AxGen,
8
+ AxChainOfThought,
9
+ AxAgent,
10
+ AxFunction,
11
+ AxAIOpenAIBase,
12
+ axModelInfoOpenAI,
13
+ AxGenOut,
14
+ } from '@digipair/ax';
15
+
16
+ class DspService {
17
+ private async prepareFunctions(functions: AxFunction[], context: any): Promise<AxFunction[]> {
18
+ return await Promise.all(
19
+ functions.map(async (f, i) => ({
20
+ ...f,
21
+ func: async (params: any) =>
22
+ await executePinsList(
23
+ f.func as any as PinsSettings[],
24
+ { ...context, params },
25
+ `${context.__PATH__}.functions[${i}]`,
26
+ ),
27
+ })),
28
+ );
29
+ }
30
+
31
+ private mergeDeltas(base: Partial<AxGenOut>, delta: Partial<AxGenOut>) {
32
+ for (const key of Object.keys(delta)) {
33
+ const baseValue = base[key];
34
+ const deltaValue = delta[key];
35
+
36
+ if (baseValue === undefined && Array.isArray(deltaValue)) {
37
+ base[key] = [...deltaValue];
38
+ } else if (Array.isArray(baseValue) && Array.isArray(deltaValue)) {
39
+ // Concatenate arrays
40
+ base[key] = [...(baseValue ?? []), ...deltaValue];
41
+ } else if (
42
+ (baseValue === undefined || typeof baseValue === 'string') &&
43
+ typeof deltaValue === 'string'
44
+ ) {
45
+ // Concatenate strings
46
+ base[key] = (baseValue ?? '') + deltaValue;
47
+ } else {
48
+ // For all other types, overwrite with the new value
49
+ base[key] = deltaValue;
50
+ }
51
+ }
52
+ return base;
53
+ }
54
+
55
+ async model(params: any, _pinsSettingsList: PinsSettings[], _context: any) {
56
+ const { name, options } = params;
57
+
58
+ const modelInstance = new AxAI({ name, ...options });
59
+
60
+ return modelInstance;
61
+ }
62
+
63
+ async modelOpenAI(params: any, _pinsSettingsList: PinsSettings[], context: any) {
64
+ const {
65
+ apiKey = context.privates.OPENAI_API_KEY ?? process.env['OPENAI_API_KEY'],
66
+ apiURL = context.privates.OPENAI_SERVER ?? process.env['OPENAI_SERVER'],
67
+ config = { model: 'gpt-4o-mini' },
68
+ supportFor = {
69
+ functions: true,
70
+ streaming: true,
71
+ hasThinkingBudget: false,
72
+ hasShowThoughts: false,
73
+ },
74
+ options,
75
+ } = params;
76
+
77
+ const modelInstance = new AxAIOpenAIBase({
78
+ apiKey,
79
+ apiURL,
80
+ modelInfo: axModelInfoOpenAI,
81
+ config,
82
+ options,
83
+ supportFor,
84
+ });
85
+
86
+ return modelInstance;
87
+ }
88
+
89
+ async modelAzureOpenAi(params: any, _pinsSettingsList: PinsSettings[], context: any) {
90
+ const {
91
+ apiKey = context.privates.AZURE_OPENAI_API_KEY ?? process.env['AZURE_OPENAI_API_KEY'],
92
+ resourceName = context.privates.AZURE_OPENAI_API_INSTANCE_NAME ??
93
+ process.env['AZURE_OPENAI_API_INSTANCE_NAME'],
94
+ deploymentName = context.privates.AZURE_OPENAI_API_DEPLOYMENT_NAME ??
95
+ process.env['AZURE_OPENAI_API_DEPLOYMENT_NAME'],
96
+ version = context.privates.AZURE_OPENAI_API_VERSION ??
97
+ process.env['AZURE_OPENAI_API_VERSION'],
98
+ config,
99
+ options,
100
+ } = params;
101
+
102
+ const modelInstance = new AxAIAzureOpenAI({
103
+ apiKey,
104
+ resourceName,
105
+ deploymentName,
106
+ version,
107
+ config,
108
+ options,
109
+ });
110
+
111
+ return modelInstance;
112
+ }
113
+
114
+ async modelOllama(params: any, _pinsSettingsList: PinsSettings[], context: any) {
115
+ const {
116
+ model,
117
+ url = context.privates.OLLAMA_SERVER
118
+ ? context.privates.OLLAMA_SERVER + '/v1'
119
+ : process.env['OLLAMA_SERVER']
120
+ ? process.env['OLLAMA_SERVER'] + '/v1'
121
+ : 'http://localhost:11434/v1',
122
+ apiKey,
123
+ config,
124
+ options,
125
+ } = params;
126
+
127
+ const modelInstance = new AxAIOllama({ model, url, apiKey, config, options });
128
+
129
+ return modelInstance;
130
+ }
131
+
132
+ async generate(params: any, _pinsSettingsList: PinsSettings[], context: any) {
133
+ const {
134
+ model = context.privates.MODEL_DSP,
135
+ functions = [],
136
+ options = {},
137
+ streaming,
138
+ signature,
139
+ input,
140
+ } = params;
141
+
142
+ const modelInstance = await executePinsList(model, context, `${context.__PATH__}.model`);
143
+ const gen = new AxGen(signature, {
144
+ functions: await this.prepareFunctions(functions, context),
145
+ });
146
+ const generator = gen.streamingForward(modelInstance, input, options);
147
+ let buffer = {} as any;
148
+ let currentVersion = 0;
149
+
150
+ for await (const item of generator) {
151
+ if (streaming) {
152
+ await executePinsList(
153
+ streaming,
154
+ { ...context, event: item },
155
+ `${context.__PATH__}.streaming`,
156
+ );
157
+ }
158
+
159
+ if (item.version !== currentVersion) {
160
+ buffer = {};
161
+ }
162
+ currentVersion = item.version;
163
+ buffer = this.mergeDeltas(buffer, item.delta);
164
+ }
165
+ const result = buffer;
166
+
167
+ // add comsumption
168
+ const ai: any = (modelInstance as any).ai ?? modelInstance;
169
+ const consumption = ai.modelUsage;
170
+ const skillLogger = require('@digipair/skill-logger');
171
+ await skillLogger.addConsumption(
172
+ context,
173
+ ai.name,
174
+ ai.defaults.model,
175
+ consumption.promptTokens,
176
+ consumption.completionTokens,
177
+ );
178
+
179
+ return result;
180
+ }
181
+
182
+ async chainOfThought(params: any, _pinsSettingsList: PinsSettings[], context: any) {
183
+ const {
184
+ model = context.privates.MODEL_DSP,
185
+ functions = [],
186
+ options = {},
187
+ streaming,
188
+ signature,
189
+ input,
190
+ } = params;
191
+
192
+ const modelInstance = await executePinsList(model, context, `${context.__PATH__}.model`);
193
+ const gen = new AxChainOfThought(signature, {
194
+ functions: await this.prepareFunctions(functions, context),
195
+ });
196
+ const generator = gen.streamingForward(modelInstance, input, options);
197
+ let buffer = {} as any;
198
+ let currentVersion = 0;
199
+
200
+ for await (const item of generator) {
201
+ if (streaming) {
202
+ await executePinsList(
203
+ streaming,
204
+ { ...context, event: item },
205
+ `${context.__PATH__}.streaming`,
206
+ );
207
+ }
208
+
209
+ if (item.version !== currentVersion) {
210
+ buffer = {};
211
+ }
212
+ currentVersion = item.version;
213
+ buffer = this.mergeDeltas(buffer, item.delta);
214
+ }
215
+ const result = buffer;
216
+
217
+ // add comsumption
218
+ const ai: any = (modelInstance as any).ai ?? modelInstance;
219
+ const consumption = ai.modelUsage;
220
+ const skillLogger = require('@digipair/skill-logger');
221
+ await skillLogger.addConsumption(
222
+ context,
223
+ ai.name,
224
+ ai.defaults.model,
225
+ consumption.promptTokens,
226
+ consumption.completionTokens,
227
+ );
228
+
229
+ return result;
230
+ }
231
+
232
+ async agent(params: any, _pinsSettingsList: PinsSettings[], context: any) {
233
+ const {
234
+ model = context.privates.MODEL_DSP,
235
+ functions = [],
236
+ agents = [],
237
+ forward = true,
238
+ options = {},
239
+ streaming,
240
+ name,
241
+ description,
242
+ signature,
243
+ input,
244
+ } = params;
245
+
246
+ const modelInstance = await executePinsList(model, context, `${context.__PATH__}.model`);
247
+ const agent = new AxAgent({
248
+ name,
249
+ description,
250
+ signature,
251
+ functions: await this.prepareFunctions(functions, context),
252
+ agents: await Promise.all(
253
+ agents.map(
254
+ async (execute: PinsSettings, i: number) =>
255
+ await executePinsList(
256
+ [{ ...execute, properties: { ...execute.properties, forward: false } }],
257
+ context,
258
+ `${context.__PATH__}.agents[${i}]`,
259
+ ),
260
+ ),
261
+ ),
262
+ });
263
+
264
+ if (!forward) {
265
+ return agent;
266
+ }
267
+
268
+ const generator = agent.streamingForward(modelInstance, input, options);
269
+ let buffer = {} as any;
270
+ let currentVersion = 0;
271
+
272
+ for await (const item of generator) {
273
+ if (streaming) {
274
+ await executePinsList(
275
+ streaming,
276
+ { ...context, event: item },
277
+ `${context.__PATH__}.streaming`,
278
+ );
279
+ }
280
+
281
+ if (item.version !== currentVersion) {
282
+ buffer = {};
283
+ }
284
+ currentVersion = item.version;
285
+ buffer = this.mergeDeltas(buffer, item.delta);
286
+ }
287
+ const result = buffer;
288
+
289
+ // add comsumption
290
+ const ai: any = (modelInstance as any).ai ?? modelInstance;
291
+ const consumption = ai.modelUsage;
292
+ const skillLogger = require('@digipair/skill-logger');
293
+ await skillLogger.addConsumption(
294
+ context,
295
+ ai.name,
296
+ ai.defaults.model,
297
+ consumption.promptTokens,
298
+ consumption.completionTokens,
299
+ );
300
+
301
+ return result;
302
+ }
303
+ }
304
+
305
+ export const model = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
306
+ new DspService().model(params, pinsSettingsList, context);
307
+
308
+ export const modelOpenAI = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
309
+ new DspService().modelOpenAI(params, pinsSettingsList, context);
310
+
311
+ export const modelAzureOpenAi = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
312
+ new DspService().modelAzureOpenAi(params, pinsSettingsList, context);
313
+
314
+ export const modelOllama = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
315
+ new DspService().modelOllama(params, pinsSettingsList, context);
316
+
317
+ export const generate = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
318
+ new DspService().generate(params, pinsSettingsList, context);
319
+
320
+ export const chainOfThought = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
321
+ new DspService().chainOfThought(params, pinsSettingsList, context);
322
+
323
+ export const agent = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
324
+ new DspService().agent(params, pinsSettingsList, context);
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "files": [],
4
+ "include": [],
5
+ "references": [
6
+ {
7
+ "path": "../skill-logger"
8
+ },
9
+ {
10
+ "path": "../engine"
11
+ },
12
+ {
13
+ "path": "./tsconfig.lib.json"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
7
+ "emitDeclarationOnly": true,
8
+ "module": "esnext",
9
+ "moduleResolution": "node",
10
+ "forceConsistentCasingInFileNames": true,
11
+ "types": ["node"]
12
+ },
13
+ "include": ["src/**/*.ts"],
14
+ "references": [
15
+ {
16
+ "path": "../skill-logger/tsconfig.lib.json"
17
+ },
18
+ {
19
+ "path": "../engine/tsconfig.lib.json"
20
+ }
21
+ ]
22
+ }
package/index.cjs.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";