@ddse/acm-sdk 0.5.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/LICENSE +21 -0
- package/README.md +221 -0
- package/dist/capability.d.ts +10 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +3 -0
- package/dist/capability.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/policy.d.ts +5 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +2 -0
- package/dist/policy.js.map +1 -0
- package/dist/registry.d.ts +6 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +3 -0
- package/dist/registry.js.map +1 -0
- package/dist/src/capability-map.d.ts +6 -0
- package/dist/src/capability-map.d.ts.map +1 -0
- package/dist/src/capability-map.js +281 -0
- package/dist/src/capability-map.js.map +1 -0
- package/dist/src/capability.d.ts +10 -0
- package/dist/src/capability.d.ts.map +1 -0
- package/dist/src/capability.js +3 -0
- package/dist/src/capability.js.map +1 -0
- package/dist/src/context-provider.d.ts +36 -0
- package/dist/src/context-provider.d.ts.map +1 -0
- package/dist/src/context-provider.js +59 -0
- package/dist/src/context-provider.js.map +1 -0
- package/dist/src/context.d.ts +42 -0
- package/dist/src/context.d.ts.map +1 -0
- package/dist/src/context.js +148 -0
- package/dist/src/context.js.map +1 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +13 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/nucleus.d.ts +105 -0
- package/dist/src/nucleus.d.ts.map +1 -0
- package/dist/src/nucleus.js +208 -0
- package/dist/src/nucleus.js.map +1 -0
- package/dist/src/policy.d.ts +5 -0
- package/dist/src/policy.d.ts.map +1 -0
- package/dist/src/policy.js +2 -0
- package/dist/src/policy.js.map +1 -0
- package/dist/src/registry.d.ts +6 -0
- package/dist/src/registry.d.ts.map +1 -0
- package/dist/src/registry.js +3 -0
- package/dist/src/registry.js.map +1 -0
- package/dist/src/stream.d.ts +8 -0
- package/dist/src/stream.d.ts.map +1 -0
- package/dist/src/stream.js +19 -0
- package/dist/src/stream.js.map +1 -0
- package/dist/src/task.d.ts +24 -0
- package/dist/src/task.d.ts.map +1 -0
- package/dist/src/task.js +11 -0
- package/dist/src/task.js.map +1 -0
- package/dist/src/tool.d.ts +5 -0
- package/dist/src/tool.d.ts.map +1 -0
- package/dist/src/tool.js +4 -0
- package/dist/src/tool.js.map +1 -0
- package/dist/src/types.d.ts +195 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +22 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +194 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/validators.d.ts +20 -0
- package/dist/src/validators.d.ts.map +1 -0
- package/dist/src/validators.js +209 -0
- package/dist/src/validators.js.map +1 -0
- package/dist/stream.d.ts +8 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +19 -0
- package/dist/stream.js.map +1 -0
- package/dist/task.d.ts +11 -0
- package/dist/task.d.ts.map +1 -0
- package/dist/task.js +9 -0
- package/dist/task.js.map +1 -0
- package/dist/tests/phase4-integration.test.d.ts +2 -0
- package/dist/tests/phase4-integration.test.d.ts.map +1 -0
- package/dist/tests/phase4-integration.test.js +115 -0
- package/dist/tests/phase4-integration.test.js.map +1 -0
- package/dist/tool.d.ts +5 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/tool.js +4 -0
- package/dist/tool.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +77 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +26 -0
- package/src/capability.ts +11 -0
- package/src/context-provider.ts +136 -0
- package/src/context.ts +190 -0
- package/src/index.ts +12 -0
- package/src/nucleus.ts +341 -0
- package/src/policy.ts +9 -0
- package/src/registry.ts +7 -0
- package/src/stream.ts +24 -0
- package/src/task.ts +38 -0
- package/src/tool.ts +6 -0
- package/src/types.ts +233 -0
- package/src/utils.ts +271 -0
- package/tests/phase4-integration.test.ts +138 -0
- package/tsconfig.json +8 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,0BAA0B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ddse/acm-sdk",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "ACM v0.5 SDK - Abstract classes and types",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/src/index.js",
|
|
7
|
+
"types": "./dist/src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/src/index.d.ts",
|
|
11
|
+
"import": "./dist/src/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"acm",
|
|
16
|
+
"sdk",
|
|
17
|
+
"types"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"test": "tsc && node ./dist/tests/phase4-integration.test.js",
|
|
23
|
+
"clean": "rm -rf dist",
|
|
24
|
+
"dev": "tsc --watch"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Abstract CapabilityRegistry class
|
|
2
|
+
import type { Capability } from './types.js';
|
|
3
|
+
import type { Task } from './task.js';
|
|
4
|
+
|
|
5
|
+
export abstract class CapabilityRegistry {
|
|
6
|
+
abstract list(): Capability[];
|
|
7
|
+
abstract has(name: string): boolean;
|
|
8
|
+
abstract resolve(name: string): Task<any, any> | undefined;
|
|
9
|
+
abstract inputSchema(name: string): unknown | undefined;
|
|
10
|
+
abstract outputSchema(name: string): unknown | undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { Nucleus } from './nucleus.js';
|
|
2
|
+
import type { RunContext, InternalContextScope } from './types.js';
|
|
3
|
+
import type { Tool } from './tool.js';
|
|
4
|
+
|
|
5
|
+
export type ContextRetrievalArtifact = {
|
|
6
|
+
type: string;
|
|
7
|
+
content: any;
|
|
8
|
+
promote?: boolean;
|
|
9
|
+
provenance?: {
|
|
10
|
+
tool?: string;
|
|
11
|
+
rationale?: string;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type ContextRetrievalResult =
|
|
17
|
+
| ContextRetrievalArtifact
|
|
18
|
+
| ContextRetrievalArtifact[]
|
|
19
|
+
| null
|
|
20
|
+
| undefined;
|
|
21
|
+
|
|
22
|
+
export type ContextRetrievalTool = Tool<any, ContextRetrievalResult>;
|
|
23
|
+
|
|
24
|
+
export type ContextRetrievalBindingOptions = {
|
|
25
|
+
match?: (directive: string) => boolean;
|
|
26
|
+
buildInput?: (
|
|
27
|
+
directive: string,
|
|
28
|
+
context: {
|
|
29
|
+
runContext?: RunContext;
|
|
30
|
+
nucleus?: Nucleus;
|
|
31
|
+
}
|
|
32
|
+
) => any;
|
|
33
|
+
autoPromote?: boolean;
|
|
34
|
+
maxArtifacts?: number;
|
|
35
|
+
describe?: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
type Binding = {
|
|
39
|
+
tool: ContextRetrievalTool;
|
|
40
|
+
match: (directive: string) => boolean;
|
|
41
|
+
buildInput: (
|
|
42
|
+
directive: string,
|
|
43
|
+
context: {
|
|
44
|
+
runContext?: RunContext;
|
|
45
|
+
nucleus?: Nucleus;
|
|
46
|
+
}
|
|
47
|
+
) => any;
|
|
48
|
+
autoPromote: boolean;
|
|
49
|
+
maxArtifacts: number;
|
|
50
|
+
describe?: string;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export class ExternalContextProviderAdapter {
|
|
54
|
+
private bindings: Binding[] = [];
|
|
55
|
+
|
|
56
|
+
register(tool: ContextRetrievalTool, options?: ContextRetrievalBindingOptions): void {
|
|
57
|
+
const match: Binding['match'] =
|
|
58
|
+
options?.match ??
|
|
59
|
+
((directive: string) =>
|
|
60
|
+
directive.startsWith(`${tool.name()}:`) || directive.startsWith(`${tool.name()}::`));
|
|
61
|
+
|
|
62
|
+
const buildInput: Binding['buildInput'] =
|
|
63
|
+
options?.buildInput ?? ((directive: string) => {
|
|
64
|
+
const separatorIndex = directive.indexOf(':');
|
|
65
|
+
const payload = separatorIndex >= 0 ? directive.slice(separatorIndex + 1) : undefined;
|
|
66
|
+
return {
|
|
67
|
+
directive,
|
|
68
|
+
payload,
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
this.bindings.push({
|
|
73
|
+
tool,
|
|
74
|
+
match,
|
|
75
|
+
buildInput,
|
|
76
|
+
autoPromote: options?.autoPromote ?? true,
|
|
77
|
+
maxArtifacts: options?.maxArtifacts ?? 16,
|
|
78
|
+
describe: options?.describe,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async fulfill(request: {
|
|
83
|
+
directives: string[];
|
|
84
|
+
scope: InternalContextScope;
|
|
85
|
+
runContext?: RunContext;
|
|
86
|
+
nucleus?: Nucleus;
|
|
87
|
+
}): Promise<void> {
|
|
88
|
+
const { directives, scope, runContext, nucleus } = request;
|
|
89
|
+
|
|
90
|
+
const unresolved: string[] = [];
|
|
91
|
+
|
|
92
|
+
for (const directive of directives) {
|
|
93
|
+
const binding = this.bindings.find(entry => entry.match(directive));
|
|
94
|
+
if (!binding) {
|
|
95
|
+
unresolved.push(directive);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const input = binding.buildInput(directive, { runContext, nucleus });
|
|
100
|
+
const result = await binding.tool.call(input);
|
|
101
|
+
if (!result) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const artifacts = Array.isArray(result) ? result : [result];
|
|
106
|
+
if (artifacts.length > binding.maxArtifacts) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
`Tool ${binding.tool.name()} returned ${artifacts.length} artifacts for directive ${directive}, exceeding limit ${binding.maxArtifacts}`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
for (const artifact of artifacts) {
|
|
113
|
+
if (!artifact || typeof artifact.type !== 'string') {
|
|
114
|
+
throw new Error(
|
|
115
|
+
`Tool ${binding.tool.name()} returned an invalid artifact for directive ${directive}`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const provenance = artifact.provenance ?? {
|
|
120
|
+
tool: binding.tool.name(),
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const artifactId = scope.addArtifact(artifact.type, artifact.content, provenance);
|
|
124
|
+
if (artifact.promote ?? binding.autoPromote) {
|
|
125
|
+
await scope.promote(artifactId);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (unresolved.length > 0) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`No context retrieval tool registered for directives: ${unresolved.join(', ')}`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// Context orchestration utilities
|
|
2
|
+
|
|
3
|
+
import { createHash } from 'crypto';
|
|
4
|
+
import type { ContextPacket, InternalContextScope, LedgerEntry } from './types.js';
|
|
5
|
+
|
|
6
|
+
export class ContextBuilder {
|
|
7
|
+
private sources: ContextPacket['sources'] = [];
|
|
8
|
+
private facts: Record<string, any> = {};
|
|
9
|
+
private assumptions: string[] = [];
|
|
10
|
+
private augmentations: ContextPacket['augmentations'] = [];
|
|
11
|
+
private provenance: ContextPacket['provenance'] = {};
|
|
12
|
+
|
|
13
|
+
addSource(uri: string, type?: string, content?: any): this {
|
|
14
|
+
const digest = this.computeDigest(content ? JSON.stringify(content) : uri);
|
|
15
|
+
this.sources!.push({ uri, digest, type });
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
addFact(key: string, value: any): this {
|
|
20
|
+
this.facts[key] = value;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
addFacts(facts: Record<string, any>): this {
|
|
25
|
+
Object.assign(this.facts, facts);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
addAssumption(assumption: string): this {
|
|
30
|
+
this.assumptions.push(assumption);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
addAugmentation(type: string, artifact: string): this {
|
|
35
|
+
this.augmentations!.push({ type, artifact });
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setProvenance(provenance: ContextPacket['provenance']): this {
|
|
40
|
+
this.provenance = provenance;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
build(version?: string): ContextPacket {
|
|
45
|
+
const packet: ContextPacket = {
|
|
46
|
+
id: this.computePacketId(),
|
|
47
|
+
version,
|
|
48
|
+
sources: this.sources,
|
|
49
|
+
facts: this.facts,
|
|
50
|
+
assumptions: this.assumptions.length > 0 ? this.assumptions : undefined,
|
|
51
|
+
augmentations: this.augmentations,
|
|
52
|
+
provenance: this.provenance,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return packet;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private computePacketId(): string {
|
|
59
|
+
// Compute SHA-256 hash of the normalized packet
|
|
60
|
+
const normalized = JSON.stringify({
|
|
61
|
+
sources: this.sources,
|
|
62
|
+
facts: this.facts,
|
|
63
|
+
assumptions: this.assumptions,
|
|
64
|
+
augmentations: this.augmentations,
|
|
65
|
+
});
|
|
66
|
+
const hash = createHash('sha256');
|
|
67
|
+
hash.update(normalized);
|
|
68
|
+
return `sha256-${hash.digest('hex')}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private computeDigest(content: string): string {
|
|
72
|
+
const hash = createHash('sha256');
|
|
73
|
+
hash.update(content);
|
|
74
|
+
return `sha256-${hash.digest('hex').substring(0, 32)}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static computeContextRef(context: ContextPacket): string {
|
|
78
|
+
// Compute full SHA-256 hash of the normalized context packet
|
|
79
|
+
const normalized = JSON.stringify({
|
|
80
|
+
sources: context.sources,
|
|
81
|
+
facts: context.facts,
|
|
82
|
+
assumptions: context.assumptions,
|
|
83
|
+
augmentations: context.augmentations,
|
|
84
|
+
});
|
|
85
|
+
const hash = createHash('sha256');
|
|
86
|
+
hash.update(normalized);
|
|
87
|
+
return hash.digest('hex');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class InternalContextScopeImpl implements InternalContextScope {
|
|
92
|
+
artifacts: Array<{
|
|
93
|
+
id: string;
|
|
94
|
+
type: string;
|
|
95
|
+
content: any;
|
|
96
|
+
digest: string;
|
|
97
|
+
provenance?: {
|
|
98
|
+
retrievedAt: number;
|
|
99
|
+
tool?: string;
|
|
100
|
+
rationale?: string;
|
|
101
|
+
};
|
|
102
|
+
}> = [];
|
|
103
|
+
|
|
104
|
+
private ledgerAppend?: (entry: LedgerEntry) => void;
|
|
105
|
+
private contextBuilder?: ContextBuilder;
|
|
106
|
+
|
|
107
|
+
constructor(ledgerAppend?: (entry: LedgerEntry) => void) {
|
|
108
|
+
this.ledgerAppend = ledgerAppend;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
addArtifact(
|
|
112
|
+
type: string,
|
|
113
|
+
content: any,
|
|
114
|
+
provenance?: {
|
|
115
|
+
tool?: string;
|
|
116
|
+
rationale?: string;
|
|
117
|
+
}
|
|
118
|
+
): string {
|
|
119
|
+
const id = `artifact-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
120
|
+
const digest = this.computeDigest(JSON.stringify(content));
|
|
121
|
+
|
|
122
|
+
this.artifacts.push({
|
|
123
|
+
id,
|
|
124
|
+
type,
|
|
125
|
+
content,
|
|
126
|
+
digest,
|
|
127
|
+
provenance: provenance
|
|
128
|
+
? {
|
|
129
|
+
retrievedAt: Date.now(),
|
|
130
|
+
...provenance,
|
|
131
|
+
}
|
|
132
|
+
: undefined,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Record to ledger
|
|
136
|
+
if (this.ledgerAppend) {
|
|
137
|
+
this.ledgerAppend({
|
|
138
|
+
id: `context-internal-${Date.now()}-${Math.random().toString(36).substring(7)}`,
|
|
139
|
+
ts: Date.now(),
|
|
140
|
+
type: 'CONTEXT_INTERNALIZED',
|
|
141
|
+
details: {
|
|
142
|
+
artifactId: id,
|
|
143
|
+
type,
|
|
144
|
+
digest,
|
|
145
|
+
provenance,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return id;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async promote(artifactId: string): Promise<void> {
|
|
154
|
+
const artifact = this.artifacts.find(a => a.id === artifactId);
|
|
155
|
+
if (!artifact) {
|
|
156
|
+
throw new Error(`Artifact not found: ${artifactId}`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// In a real implementation, this would create a new Context Packet version
|
|
160
|
+
// and append to the context builder
|
|
161
|
+
if (this.contextBuilder) {
|
|
162
|
+
this.contextBuilder.addAugmentation(artifact.type, artifact.id);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Log promotion
|
|
166
|
+
if (this.ledgerAppend) {
|
|
167
|
+
this.ledgerAppend({
|
|
168
|
+
id: `context-promote-${Date.now()}-${Math.random().toString(36).substring(7)}`,
|
|
169
|
+
ts: Date.now(),
|
|
170
|
+
type: 'CONTEXT_INTERNALIZED',
|
|
171
|
+
details: {
|
|
172
|
+
action: 'promote',
|
|
173
|
+
artifactId,
|
|
174
|
+
digest: artifact.digest,
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
getArtifact(id: string): any {
|
|
181
|
+
const artifact = this.artifacts.find(a => a.id === id);
|
|
182
|
+
return artifact?.content;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private computeDigest(content: string): string {
|
|
186
|
+
const hash = createHash('sha256');
|
|
187
|
+
hash.update(content);
|
|
188
|
+
return hash.digest('hex').substring(0, 32);
|
|
189
|
+
}
|
|
190
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SDK exports
|
|
2
|
+
export * from './types.js';
|
|
3
|
+
export * from './tool.js';
|
|
4
|
+
export * from './task.js';
|
|
5
|
+
export * from './capability.js';
|
|
6
|
+
export * from './registry.js';
|
|
7
|
+
export * from './policy.js';
|
|
8
|
+
export * from './stream.js';
|
|
9
|
+
export * from './nucleus.js';
|
|
10
|
+
export * from './context.js';
|
|
11
|
+
export * from './context-provider.js';
|
|
12
|
+
export * from './utils.js';
|