@exellix/ai-tasks 8.4.1 → 8.4.3
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/.docs/DOWNSTREAM_ENV.md +42 -0
- package/.docs/FEEDBACK_TO_CLIENT_DOWNSTREAM_FIXES.md +64 -0
- package/.docs/INTERMEDIATE_STEPS.md +82 -0
- package/.docs/activity-structure.md +31 -0
- package/.docs/ai-task-ai-scoping-spec.md +338 -0
- package/.docs/ai-tasks-model-profile-aliases-7x.md +74 -0
- package/.docs/blockers-and-issues.md +346 -0
- package/.docs/building-runTask-sdk.md +659 -0
- package/.docs/building-skill-execution-orchestrator.md +968 -0
- package/.docs/code-used-before/run-task.txt +39 -0
- package/.docs/code-used-before/task-executor.ts.old +57 -0
- package/.docs/code-used-before/test-run-task.ts.old +42 -0
- package/.docs/code-used-before/types.txt +23 -0
- package/.docs/env-ready-policy.md +40 -0
- package/.docs/flow-io/flow-README.md +76 -0
- package/.docs/flow-io/narrix.md +124 -0
- package/.docs/flow-io/web-scoping.md +135 -0
- package/.docs/flow-io/xynthesis-post.md +154 -0
- package/.docs/flow-io/xynthesis-pre.md +181 -0
- package/.docs/gap-analysis.md +201 -0
- package/.docs/integration-facts-ai-tasks.md +109 -0
- package/.docs/investigation/ai-skills.md +170 -0
- package/.docs/investigation/external-packages-assignments.md +66 -0
- package/.docs/investigation/integration-summary.md +20 -0
- package/.docs/investigation/narrix-catalox.md +29 -0
- package/.docs/investigation/workplan-close-graph-engine-gaps.md +101 -0
- package/.docs/logging-stack.md +30 -0
- package/.docs/memory-narrix-adapter-developer-guide.md +402 -0
- package/.docs/memory-narrix-adapter-requirements.md +112 -0
- package/.docs/narrix-context-consumption-gap.md +184 -0
- package/.docs/narrix-context-downstream-report.md +30 -0
- package/.docs/narrix-ingest-and-packs-library-spec.md +240 -0
- package/.docs/narrix-record-input-current-design.md +48 -0
- package/.docs/pacakge.md +48 -0
- package/.docs/possible-components/README.md +11 -0
- package/.docs/possible-components/integration/README.md +10 -0
- package/.docs/possible-components/integration/gaps-when-merging.md +16 -0
- package/.docs/possible-components/integration/platform.md +54 -0
- package/.docs/possible-components/integration/reintegrate-into-ai-tasks.md +26 -0
- package/.docs/possible-components/integration/roadmap-and-checklists.md +54 -0
- package/.docs/possible-components/post-component/README.md +18 -0
- package/.docs/possible-components/post-component/builder-guide.md +175 -0
- package/.docs/possible-components/post-component/gaps-and-artifacts.md +52 -0
- package/.docs/possible-components/post-component/handler-audit.md +47 -0
- package/.docs/possible-components/post-component/handler-polish.md +41 -0
- package/.docs/possible-components/post-component/unified-protocol.md +59 -0
- package/.docs/possible-components/pre-component/README.md +22 -0
- package/.docs/possible-components/pre-component/builder-guide.md +127 -0
- package/.docs/possible-components/pre-component/gaps-and-artifacts.md +35 -0
- package/.docs/possible-components/pre-component/handler-ai-scoping.md +45 -0
- package/.docs/possible-components/pre-component/handler-narrix-preprocessor.md +49 -0
- package/.docs/possible-components/pre-component/handler-narrix-system2.md +35 -0
- package/.docs/possible-components/pre-component/handler-synthesized-context.md +65 -0
- package/.docs/possible-components/pre-component/handler-web-scope.md +29 -0
- package/.docs/possible-components/pre-component/unified-protocol.md +89 -0
- package/.docs/prefer-openrouter-routing-policy.md +132 -0
- package/.docs/questions-for-ai-skills.md +123 -0
- package/.docs/realtime-narrixing-gap-analysis.md +40 -0
- package/.docs/realtime-narrixing.md +433 -0
- package/.docs/run-context-object.md +32 -0
- package/.docs/session-id-usage.md +26 -0
- package/.docs/skill-library-spec.md +249 -0
- package/.docs/synthesized-context-strategy-spec.md +906 -0
- package/.docs/upstream-issue/2026-03-21_woroces-ai-tasks_ISSUE-006_web-scope-question-from-cni-entity.md +46 -0
- package/.docs/web-scopper-embed.md +93 -0
- package/.docs/xynthesis-wiring-and-io.md +12 -0
- package/README.md +15 -13
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/runPostStepLlmCall.d.ts.map +1 -1
- package/dist/internal/runPostStepLlmCall.js +4 -2
- package/dist/internal/runPostStepLlmCall.js.map +1 -1
- package/dist/invocation/resolveProfileInvocationRouting.js +2 -2
- package/dist/invocation/resolveProfileInvocationRouting.js.map +1 -1
- package/dist/utils/aiProfileModelFormat.d.ts +2 -2
- package/dist/utils/aiProfileModelFormat.js +2 -2
- package/dist/utils/aiProfilesCatalog.d.ts +16 -0
- package/dist/utils/aiProfilesCatalog.d.ts.map +1 -0
- package/dist/utils/aiProfilesCatalog.js +23 -0
- package/dist/utils/aiProfilesCatalog.js.map +1 -0
- package/dist/utils/resolveAiProfileModel.d.ts +2 -2
- package/dist/utils/resolveAiProfileModel.d.ts.map +1 -1
- package/dist/utils/resolveAiProfileModel.js +5 -5
- package/dist/utils/resolveAiProfileModel.js.map +1 -1
- package/dist/utils/routeModelConfigSlots.d.ts +3 -1
- package/dist/utils/routeModelConfigSlots.d.ts.map +1 -1
- package/dist/utils/routeModelConfigSlots.js +2 -1
- package/dist/utils/routeModelConfigSlots.js.map +1 -1
- package/documenations/upstream-feature-requests/README.md +2 -1
- package/documenations/upstream-feature-requests/ai-tasks-wrap-up-after-upstream.md +7 -4
- package/documenations/upstream-feature-requests/xynthesis-ai-profiles-2.1-import-break.md +324 -0
- package/documenations/upstream-feature-requests/xynthesis-orchestrator-invoke-contract-4.2.md +6 -4
- package/package.json +3 -2
|
@@ -0,0 +1,659 @@
|
|
|
1
|
+
# Building a Minimal SDK with Only `runTask` Functionality
|
|
2
|
+
|
|
3
|
+
This guide provides step-by-step instructions for creating a new SDK that uses `@woroces/ai-skills` and implements **only** the `runTask` functionality. This is useful when you want a lightweight wrapper that focuses exclusively on task execution without the full feature set of the main SDK.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
1. [Overview](#overview)
|
|
8
|
+
2. [Prerequisites](#prerequisites)
|
|
9
|
+
3. [Project Setup](#project-setup)
|
|
10
|
+
4. [Understanding `runTask`](#understanding-runtask)
|
|
11
|
+
5. [Implementation Guide](#implementation-guide)
|
|
12
|
+
6. [Complete Example](#complete-example)
|
|
13
|
+
7. [Testing](#testing)
|
|
14
|
+
8. [Advanced Configuration](#advanced-configuration)
|
|
15
|
+
9. [Troubleshooting](#troubleshooting)
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Overview
|
|
20
|
+
|
|
21
|
+
The `runTask` method is a specialized execution method that:
|
|
22
|
+
- Executes tasks with a specific execution strategy (currently only `DIRECT`)
|
|
23
|
+
- Enriches memories with scoping data (if Context Manager is available)
|
|
24
|
+
- Generates context markdown from enriched memories
|
|
25
|
+
- Delegates to the underlying skill executor
|
|
26
|
+
- Returns structured FlexMD responses
|
|
27
|
+
|
|
28
|
+
**Key Difference from `runSkill`**: `runTask` includes additional context enrichment steps and supports execution types, making it suitable for more complex orchestration scenarios.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Prerequisites
|
|
33
|
+
|
|
34
|
+
Before starting, ensure you have:
|
|
35
|
+
|
|
36
|
+
- **Node.js** >= 18.0.0
|
|
37
|
+
- **npm** or **yarn** package manager
|
|
38
|
+
- **TypeScript** knowledge
|
|
39
|
+
- Access to GitHub Package Registry (for installing `@woroces/ai-skills`)
|
|
40
|
+
- A GitHub token with package read permissions (if using remote content registry)
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Project Setup
|
|
45
|
+
|
|
46
|
+
### Step 1: Initialize Your Project
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
mkdir my-task-sdk
|
|
50
|
+
cd my-task-sdk
|
|
51
|
+
npm init -y
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Step 2: Install TypeScript and Build Tools
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install --save-dev typescript @types/node ts-node
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Step 3: Configure TypeScript
|
|
61
|
+
|
|
62
|
+
Create `tsconfig.json`:
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"compilerOptions": {
|
|
67
|
+
"target": "ES2020",
|
|
68
|
+
"module": "commonjs",
|
|
69
|
+
"lib": ["ES2020"],
|
|
70
|
+
"outDir": "./dist",
|
|
71
|
+
"rootDir": "./src",
|
|
72
|
+
"strict": true,
|
|
73
|
+
"esModuleInterop": true,
|
|
74
|
+
"skipLibCheck": true,
|
|
75
|
+
"forceConsistentCasingInFileNames": true,
|
|
76
|
+
"declaration": true,
|
|
77
|
+
"declarationMap": true,
|
|
78
|
+
"sourceMap": true,
|
|
79
|
+
"resolveJsonModule": true
|
|
80
|
+
},
|
|
81
|
+
"include": ["src/**/*"],
|
|
82
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts"]
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Step 4: Configure npm Registry for GitHub Packages
|
|
87
|
+
|
|
88
|
+
Create `.npmrc` file:
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
@woroces:registry=https://npm.pkg.github.com
|
|
92
|
+
@athenices:registry=https://npm.pkg.github.com
|
|
93
|
+
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN_HERE
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Replace `YOUR_GITHUB_TOKEN_HERE` with your GitHub personal access token that has `read:packages` permission.
|
|
97
|
+
|
|
98
|
+
### Step 5: Install Core Dependencies
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npm install @woroces/ai-skills @athenices/ai-gateway
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Note**: The `@woroces/ai-skills` package will automatically pull in its dependencies:
|
|
105
|
+
- `@athenices/ai-gateway` (already listed)
|
|
106
|
+
- `@athenices/execution-memory-manager`
|
|
107
|
+
- `@athenices/xontext` (optional, for context enrichment)
|
|
108
|
+
- `logs-gateway`
|
|
109
|
+
- `nx-config2`
|
|
110
|
+
- `nx-helpers`
|
|
111
|
+
|
|
112
|
+
### Step 6: Update package.json Scripts
|
|
113
|
+
|
|
114
|
+
Add build and development scripts:
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"scripts": {
|
|
119
|
+
"build": "tsc",
|
|
120
|
+
"dev": "ts-node src/index.ts",
|
|
121
|
+
"prepublishOnly": "npm run build"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Understanding `runTask`
|
|
129
|
+
|
|
130
|
+
### API Signature
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
async runTask<TParsed = any>(
|
|
134
|
+
input: RunTaskRequest
|
|
135
|
+
): Promise<RunSkillResponse<TParsed>>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Input Interface: `RunTaskRequest`
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
interface RunTaskRequest {
|
|
142
|
+
skillKey: string; // "skills/professional-answer" or "tasks/..."
|
|
143
|
+
input: Record<string, any> | string; // Task input data
|
|
144
|
+
executionType: ExecutionType; // Currently only ExecutionType.DIRECT
|
|
145
|
+
|
|
146
|
+
// Optional fields
|
|
147
|
+
variables?: Record<string, any>; // Contextual variables (e.g., orgName, tone)
|
|
148
|
+
context?: Record<string, any> | string; // Additional context
|
|
149
|
+
knowledge?: Record<string, any>; // Knowledge base data
|
|
150
|
+
|
|
151
|
+
// Memory management
|
|
152
|
+
jobMemory?: JobHistory; // History of all previous task results
|
|
153
|
+
taskMemory?: TaskHistory; // History of skills executed up to this task
|
|
154
|
+
|
|
155
|
+
// Identifiers
|
|
156
|
+
jobId?: string;
|
|
157
|
+
agentId?: string;
|
|
158
|
+
skillId?: string;
|
|
159
|
+
masterSkillId?: string;
|
|
160
|
+
masterSkillActivityId?: string;
|
|
161
|
+
|
|
162
|
+
// Configuration
|
|
163
|
+
timeoutMs?: number; // Request timeout in milliseconds
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Output Interface: `RunSkillResponse<TParsed>`
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
interface RunSkillResponse<TParsed = any> {
|
|
171
|
+
skillKey: string; // The skill key that was executed
|
|
172
|
+
rawText: string; // Raw response from the gateway
|
|
173
|
+
flexMd: {
|
|
174
|
+
frame: string; // FlexMD frame name (e.g., "professional-answer")
|
|
175
|
+
payloads: Record<string, string>; // Parsed payloads from FlexMD
|
|
176
|
+
};
|
|
177
|
+
parsed: TParsed; // Typed parsed data (same as payloads by default)
|
|
178
|
+
metadata: {
|
|
179
|
+
instructionVersion?: string; // Version of the instruction used
|
|
180
|
+
activityId?: string; // Unique activity identifier
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### ExecutionType Enum
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
enum ExecutionType {
|
|
189
|
+
DIRECT = "direct" // Currently the only supported type
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### How `runTask` Works Internally
|
|
194
|
+
|
|
195
|
+
1. **Extract Task ID**: Removes `"tasks/"` prefix from `skillKey` if present
|
|
196
|
+
2. **Build Memory Bundle**: Combines `jobMemory` and `taskMemory`
|
|
197
|
+
3. **Enrich Memories** (if Context Manager available):
|
|
198
|
+
- Retrieves scoping definitions for the task
|
|
199
|
+
- Executes scoping queries
|
|
200
|
+
- Integrates results into memory bundle
|
|
201
|
+
4. **Generate Context Markdown** (if Context Manager available):
|
|
202
|
+
- Uses context maps to generate markdown from enriched memories
|
|
203
|
+
5. **Execute Task**: Delegates to `TaskExecutor` which:
|
|
204
|
+
- For `DIRECT` type: Passes through to `SkillExecutor`
|
|
205
|
+
- `SkillExecutor` invokes the AI Gateway
|
|
206
|
+
- Parses FlexMD response
|
|
207
|
+
- Returns structured result
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## Implementation Guide
|
|
212
|
+
|
|
213
|
+
### Step 1: Create the Main SDK Class
|
|
214
|
+
|
|
215
|
+
Create `src/task-sdk.ts`:
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
import {
|
|
219
|
+
XeonoxSkillsClient,
|
|
220
|
+
RunTaskRequest,
|
|
221
|
+
RunSkillResponse,
|
|
222
|
+
ExecutionType
|
|
223
|
+
} from "@woroces/ai-skills";
|
|
224
|
+
import type { XeonoxSkillsClientOptions } from "@woroces/ai-skills";
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Minimal Task SDK
|
|
228
|
+
*
|
|
229
|
+
* A lightweight wrapper around @woroces/ai-skills that provides
|
|
230
|
+
* only the runTask functionality.
|
|
231
|
+
*/
|
|
232
|
+
export class TaskSDK {
|
|
233
|
+
private client: XeonoxSkillsClient;
|
|
234
|
+
|
|
235
|
+
constructor(options?: XeonoxSkillsClientOptions) {
|
|
236
|
+
// Initialize the underlying client
|
|
237
|
+
// The client handles all the complexity: gateway setup, registry management, etc.
|
|
238
|
+
this.client = new XeonoxSkillsClient(options);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Execute a task with the specified execution type.
|
|
243
|
+
*
|
|
244
|
+
* @param request The task execution request
|
|
245
|
+
* @returns Promise resolving to the task response
|
|
246
|
+
*/
|
|
247
|
+
async runTask<TParsed = any>(
|
|
248
|
+
request: RunTaskRequest
|
|
249
|
+
): Promise<RunSkillResponse<TParsed>> {
|
|
250
|
+
// Ensure executionType is set (default to DIRECT if not provided)
|
|
251
|
+
const taskRequest: RunTaskRequest = {
|
|
252
|
+
...request,
|
|
253
|
+
executionType: request.executionType || ExecutionType.DIRECT
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// Delegate to the underlying client
|
|
257
|
+
return this.client.runTask<TParsed>(taskRequest);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Convenience method for direct task execution.
|
|
262
|
+
*
|
|
263
|
+
* @param skillKey The skill key to execute
|
|
264
|
+
* @param input The input data
|
|
265
|
+
* @param options Optional additional parameters
|
|
266
|
+
*/
|
|
267
|
+
async executeDirect<TParsed = any>(
|
|
268
|
+
skillKey: string,
|
|
269
|
+
input: Record<string, any> | string,
|
|
270
|
+
options?: {
|
|
271
|
+
variables?: Record<string, any>;
|
|
272
|
+
context?: Record<string, any> | string;
|
|
273
|
+
knowledge?: Record<string, any>;
|
|
274
|
+
jobMemory?: any;
|
|
275
|
+
taskMemory?: any;
|
|
276
|
+
jobId?: string;
|
|
277
|
+
agentId?: string;
|
|
278
|
+
timeoutMs?: number;
|
|
279
|
+
}
|
|
280
|
+
): Promise<RunSkillResponse<TParsed>> {
|
|
281
|
+
return this.runTask<TParsed>({
|
|
282
|
+
skillKey,
|
|
283
|
+
input,
|
|
284
|
+
executionType: ExecutionType.DIRECT,
|
|
285
|
+
...options
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Re-export types for convenience
|
|
291
|
+
export type { RunTaskRequest, RunSkillResponse } from "@woroces/ai-skills";
|
|
292
|
+
export { ExecutionType } from "@woroces/ai-skills";
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Step 2: Create the Main Entry Point
|
|
296
|
+
|
|
297
|
+
Create `src/index.ts`:
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
export { TaskSDK } from "./task-sdk";
|
|
301
|
+
export type { RunTaskRequest, RunSkillResponse } from "@woroces/ai-skills";
|
|
302
|
+
export { ExecutionType } from "@woroces/ai-skills";
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Step 3: Update package.json
|
|
306
|
+
|
|
307
|
+
Add proper metadata:
|
|
308
|
+
|
|
309
|
+
```json
|
|
310
|
+
{
|
|
311
|
+
"name": "my-task-sdk",
|
|
312
|
+
"version": "1.0.0",
|
|
313
|
+
"description": "Minimal SDK for task execution using @woroces/ai-skills",
|
|
314
|
+
"main": "dist/index.js",
|
|
315
|
+
"types": "dist/index.d.ts",
|
|
316
|
+
"files": ["dist"],
|
|
317
|
+
"keywords": ["ai", "tasks", "llm", "skills"],
|
|
318
|
+
"author": "Your Name",
|
|
319
|
+
"license": "ISC"
|
|
320
|
+
}
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
## Complete Example
|
|
326
|
+
|
|
327
|
+
### Example 1: Basic Usage
|
|
328
|
+
|
|
329
|
+
Create `examples/basic-usage.ts`:
|
|
330
|
+
|
|
331
|
+
```typescript
|
|
332
|
+
import { TaskSDK, ExecutionType } from "../src";
|
|
333
|
+
import * as dotenv from "dotenv";
|
|
334
|
+
|
|
335
|
+
dotenv.config();
|
|
336
|
+
|
|
337
|
+
async function basicExample() {
|
|
338
|
+
// Initialize the SDK
|
|
339
|
+
const sdk = new TaskSDK({
|
|
340
|
+
packageName: "MY-TASK-SDK",
|
|
341
|
+
enableContentRegistry: true,
|
|
342
|
+
contentRegistryLocalPath: "./.metadata" // or use remote registry
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// Execute a task
|
|
346
|
+
const result = await sdk.runTask({
|
|
347
|
+
skillKey: "skills/professional-answer",
|
|
348
|
+
executionType: ExecutionType.DIRECT,
|
|
349
|
+
input: {
|
|
350
|
+
question: "What is the capital of France?"
|
|
351
|
+
},
|
|
352
|
+
variables: {
|
|
353
|
+
orgName: "MyOrganization",
|
|
354
|
+
tone: "professional"
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
console.log("Task executed successfully!");
|
|
359
|
+
console.log("Frame:", result.flexMd.frame);
|
|
360
|
+
console.log("Payloads:", result.flexMd.payloads);
|
|
361
|
+
console.log("Parsed:", result.parsed);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
basicExample().catch(console.error);
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Example 2: Using Convenience Method
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
import { TaskSDK } from "../src";
|
|
371
|
+
|
|
372
|
+
async function convenienceExample() {
|
|
373
|
+
const sdk = new TaskSDK({
|
|
374
|
+
enableContentRegistry: true
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
const result = await sdk.executeDirect(
|
|
378
|
+
"skills/professional-answer",
|
|
379
|
+
{ question: "Explain quantum computing" },
|
|
380
|
+
{
|
|
381
|
+
variables: { orgName: "TechCorp" },
|
|
382
|
+
jobId: "job-123",
|
|
383
|
+
agentId: "agent-abc"
|
|
384
|
+
}
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
// Access the structured response
|
|
388
|
+
const shortAnswer = result.flexMd.payloads.shortAnswer;
|
|
389
|
+
const fullAnswer = result.flexMd.payloads.fullAnswer;
|
|
390
|
+
|
|
391
|
+
console.log("Short Answer:", shortAnswer);
|
|
392
|
+
console.log("Full Answer:", fullAnswer);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
convenienceExample().catch(console.error);
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### Example 3: With Memory Management
|
|
399
|
+
|
|
400
|
+
```typescript
|
|
401
|
+
import { TaskSDK, ExecutionType } from "../src";
|
|
402
|
+
import type { JobHistory, TaskHistory } from "@athenices/execution-memory-manager";
|
|
403
|
+
|
|
404
|
+
async function withMemoryExample() {
|
|
405
|
+
const sdk = new TaskSDK();
|
|
406
|
+
|
|
407
|
+
// Build up memory from previous tasks
|
|
408
|
+
const jobMemory: JobHistory = {
|
|
409
|
+
// Previous task results
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
const taskMemory: TaskHistory = {
|
|
413
|
+
// Previous skill executions
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
const result = await sdk.runTask({
|
|
417
|
+
skillKey: "skills/professional-decision",
|
|
418
|
+
executionType: ExecutionType.DIRECT,
|
|
419
|
+
input: {
|
|
420
|
+
scenario: "Should we migrate to cloud?"
|
|
421
|
+
},
|
|
422
|
+
variables: {
|
|
423
|
+
orgName: "EnterpriseCorp"
|
|
424
|
+
},
|
|
425
|
+
jobMemory,
|
|
426
|
+
taskMemory,
|
|
427
|
+
jobId: "job-456"
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
console.log("Decision:", result.parsed);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
withMemoryExample().catch(console.error);
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
---
|
|
437
|
+
|
|
438
|
+
## Testing
|
|
439
|
+
|
|
440
|
+
### Step 1: Create Test File
|
|
441
|
+
|
|
442
|
+
Create `src/task-sdk.test.ts`:
|
|
443
|
+
|
|
444
|
+
```typescript
|
|
445
|
+
import { TaskSDK, ExecutionType } from "./task-sdk";
|
|
446
|
+
import * as dotenv from "dotenv";
|
|
447
|
+
|
|
448
|
+
dotenv.config();
|
|
449
|
+
|
|
450
|
+
describe("TaskSDK", () => {
|
|
451
|
+
let sdk: TaskSDK;
|
|
452
|
+
|
|
453
|
+
beforeAll(() => {
|
|
454
|
+
sdk = new TaskSDK({
|
|
455
|
+
packageName: "TEST-SDK",
|
|
456
|
+
enableContentRegistry: true,
|
|
457
|
+
contentRegistryLocalPath: "./.metadata"
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
test("should execute a direct task", async () => {
|
|
462
|
+
const result = await sdk.runTask({
|
|
463
|
+
skillKey: "skills/professional-answer",
|
|
464
|
+
executionType: ExecutionType.DIRECT,
|
|
465
|
+
input: {
|
|
466
|
+
question: "What is 2+2?"
|
|
467
|
+
},
|
|
468
|
+
variables: {
|
|
469
|
+
orgName: "TestOrg"
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
expect(result).toBeDefined();
|
|
474
|
+
expect(result.skillKey).toBe("skills/professional-answer");
|
|
475
|
+
expect(result.flexMd).toBeDefined();
|
|
476
|
+
expect(result.flexMd.frame).toBeDefined();
|
|
477
|
+
expect(result.flexMd.payloads).toBeDefined();
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
test("should use convenience method", async () => {
|
|
481
|
+
const result = await sdk.executeDirect(
|
|
482
|
+
"skills/professional-answer",
|
|
483
|
+
{ question: "Test question" }
|
|
484
|
+
);
|
|
485
|
+
|
|
486
|
+
expect(result).toBeDefined();
|
|
487
|
+
expect(result.skillKey).toBe("skills/professional-answer");
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
### Step 2: Install Testing Dependencies
|
|
493
|
+
|
|
494
|
+
```bash
|
|
495
|
+
npm install --save-dev jest @types/jest ts-jest
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
### Step 3: Configure Jest
|
|
499
|
+
|
|
500
|
+
Create `jest.config.js`:
|
|
501
|
+
|
|
502
|
+
```javascript
|
|
503
|
+
module.exports = {
|
|
504
|
+
preset: 'ts-jest',
|
|
505
|
+
testEnvironment: 'node',
|
|
506
|
+
roots: ['<rootDir>/src'],
|
|
507
|
+
testMatch: ['**/*.test.ts'],
|
|
508
|
+
collectCoverageFrom: ['src/**/*.ts', '!src/**/*.test.ts']
|
|
509
|
+
};
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
---
|
|
513
|
+
|
|
514
|
+
## Advanced Configuration
|
|
515
|
+
|
|
516
|
+
### Environment Variables
|
|
517
|
+
|
|
518
|
+
The SDK uses environment variables for automatic configuration (ERC mode):
|
|
519
|
+
|
|
520
|
+
```bash
|
|
521
|
+
# Required for GitHub-based content registry
|
|
522
|
+
export GITHUB_TOKEN=your_github_token
|
|
523
|
+
export GITHUB_REPO_URL=https://github.com/your-org/content-registry
|
|
524
|
+
|
|
525
|
+
# AI Provider Keys (at least one required)
|
|
526
|
+
export OPENAI_API_KEY=your_openai_key
|
|
527
|
+
# OR
|
|
528
|
+
export GROK_API_KEY=your_grok_key
|
|
529
|
+
|
|
530
|
+
# Optional: MongoDB for context enrichment
|
|
531
|
+
export MONGODB_URI=mongodb://localhost:27017/your-db
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
### Custom Gateway Configuration
|
|
535
|
+
|
|
536
|
+
You can provide a pre-configured gateway:
|
|
537
|
+
|
|
538
|
+
```typescript
|
|
539
|
+
import { AIGateway } from "@athenices/ai-gateway";
|
|
540
|
+
import { TaskSDK } from "./src";
|
|
541
|
+
|
|
542
|
+
// Create custom gateway
|
|
543
|
+
const gateway = new AIGateway({
|
|
544
|
+
packageName: "CUSTOM-GATEWAY",
|
|
545
|
+
enableActivityTracking: true,
|
|
546
|
+
enableContentRegistry: true,
|
|
547
|
+
// ... other gateway options
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
// Use it in the SDK
|
|
551
|
+
const sdk = new TaskSDK({
|
|
552
|
+
gateway: gateway
|
|
553
|
+
});
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
### Local Development Mode
|
|
557
|
+
|
|
558
|
+
For offline development:
|
|
559
|
+
|
|
560
|
+
```typescript
|
|
561
|
+
const sdk = new TaskSDK({
|
|
562
|
+
enableContentRegistry: true,
|
|
563
|
+
contentRegistryLocalPath: "./local-metadata",
|
|
564
|
+
forceLocal: true, // Bypass remote registry
|
|
565
|
+
forceCreateRootDirectory: true // Auto-create directories
|
|
566
|
+
});
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
---
|
|
570
|
+
|
|
571
|
+
## Troubleshooting
|
|
572
|
+
|
|
573
|
+
### Issue: "Content not found" Error
|
|
574
|
+
|
|
575
|
+
**Problem**: The skill key cannot be resolved.
|
|
576
|
+
|
|
577
|
+
**Solutions**:
|
|
578
|
+
1. Verify the skill key format: `"skills/professional-answer"` (not `"professional-answer"`)
|
|
579
|
+
2. Ensure content registry contains the skill at the expected path
|
|
580
|
+
3. Check `contentRegistryLocalPath` if using local registry
|
|
581
|
+
4. Verify `GITHUB_TOKEN` and `GITHUB_REPO_URL` if using remote registry
|
|
582
|
+
|
|
583
|
+
### Issue: "Repository not accessible"
|
|
584
|
+
|
|
585
|
+
**Problem**: Cannot connect to GitHub content registry.
|
|
586
|
+
|
|
587
|
+
**Solutions**:
|
|
588
|
+
1. Verify `GITHUB_TOKEN` has correct permissions (`repo` scope for private repos)
|
|
589
|
+
2. Check `GITHUB_REPO_URL` points to an existing repository
|
|
590
|
+
3. Ensure repository is accessible (not private without proper token)
|
|
591
|
+
|
|
592
|
+
### Issue: "Unsupported execution type"
|
|
593
|
+
|
|
594
|
+
**Problem**: Using an execution type other than `DIRECT`.
|
|
595
|
+
|
|
596
|
+
**Solution**: Currently only `ExecutionType.DIRECT` is supported. Ensure you're using:
|
|
597
|
+
```typescript
|
|
598
|
+
executionType: ExecutionType.DIRECT
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
### Issue: "Environment validation failed"
|
|
602
|
+
|
|
603
|
+
**Problem**: Missing required environment variables.
|
|
604
|
+
|
|
605
|
+
**Solutions**:
|
|
606
|
+
1. Ensure at least one AI provider key is set (`OPENAI_API_KEY` or `GROK_API_KEY`)
|
|
607
|
+
2. If using remote registry, set `GITHUB_TOKEN` and `GITHUB_REPO_URL`
|
|
608
|
+
3. Check `.env` file is loaded (if using `dotenv`)
|
|
609
|
+
|
|
610
|
+
### Issue: TypeScript compilation errors
|
|
611
|
+
|
|
612
|
+
**Problem**: Type definitions not found.
|
|
613
|
+
|
|
614
|
+
**Solutions**:
|
|
615
|
+
1. Ensure `@woroces/ai-skills` is installed: `npm install @woroces/ai-skills`
|
|
616
|
+
2. Check `tsconfig.json` includes proper module resolution
|
|
617
|
+
3. Verify `skipLibCheck: true` in `tsconfig.json` if needed
|
|
618
|
+
|
|
619
|
+
---
|
|
620
|
+
|
|
621
|
+
## Summary
|
|
622
|
+
|
|
623
|
+
You've now created a minimal SDK that:
|
|
624
|
+
|
|
625
|
+
1. ✅ Wraps `@woroces/ai-skills` with a focused API
|
|
626
|
+
2. ✅ Provides only `runTask` functionality
|
|
627
|
+
3. ✅ Includes convenience methods for common use cases
|
|
628
|
+
4. ✅ Handles all underlying complexity (gateway, registry, parsing)
|
|
629
|
+
5. ✅ Supports both local and remote content registries
|
|
630
|
+
6. ✅ Includes proper TypeScript types
|
|
631
|
+
|
|
632
|
+
### Key Takeaways
|
|
633
|
+
|
|
634
|
+
- **Minimal Surface Area**: Your SDK only exposes `runTask`, keeping the API simple
|
|
635
|
+
- **Full Power Underneath**: You still get all the benefits of the full SDK (context enrichment, memory management, FlexMD parsing)
|
|
636
|
+
- **Easy to Extend**: You can add more methods later if needed
|
|
637
|
+
- **Type Safe**: Full TypeScript support with proper type inference
|
|
638
|
+
|
|
639
|
+
### Next Steps
|
|
640
|
+
|
|
641
|
+
1. Add error handling wrappers
|
|
642
|
+
2. Implement retry logic
|
|
643
|
+
3. Add request/response logging
|
|
644
|
+
4. Create additional convenience methods
|
|
645
|
+
5. Add validation for inputs
|
|
646
|
+
6. Implement caching if needed
|
|
647
|
+
|
|
648
|
+
---
|
|
649
|
+
|
|
650
|
+
## Additional Resources
|
|
651
|
+
|
|
652
|
+
- [@woroces/ai-skills README](../README.md) - Full SDK documentation
|
|
653
|
+
- [FlexMD Format Documentation](../docs/metadata.md) - Understanding FlexMD responses
|
|
654
|
+
- [Content Registry Guide](../README.md#content-registry) - Setting up content registry
|
|
655
|
+
- [AI Gateway Documentation](https://github.com/athenices/ai-gateway) - Understanding the underlying gateway
|
|
656
|
+
|
|
657
|
+
---
|
|
658
|
+
|
|
659
|
+
**Questions?** Check the main SDK documentation or open an issue in the repository.
|