@hazeljs/organism 2.0.6
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/README.md +205 -0
- package/dist/__tests__/organism.embedding.test.d.ts +2 -0
- package/dist/__tests__/organism.embedding.test.d.ts.map +1 -0
- package/dist/__tests__/organism.embedding.test.js +166 -0
- package/dist/__tests__/organism.embedding.test.js.map +1 -0
- package/dist/__tests__/organism.phase1.test.d.ts +2 -0
- package/dist/__tests__/organism.phase1.test.d.ts.map +1 -0
- package/dist/__tests__/organism.phase1.test.js +375 -0
- package/dist/__tests__/organism.phase1.test.js.map +1 -0
- package/dist/__tests__/organism.phase2-3.test.d.ts +2 -0
- package/dist/__tests__/organism.phase2-3.test.d.ts.map +1 -0
- package/dist/__tests__/organism.phase2-3.test.js +320 -0
- package/dist/__tests__/organism.phase2-3.test.js.map +1 -0
- package/dist/__tests__/organism.phase4.test.d.ts +2 -0
- package/dist/__tests__/organism.phase4.test.d.ts.map +1 -0
- package/dist/__tests__/organism.phase4.test.js +217 -0
- package/dist/__tests__/organism.phase4.test.js.map +1 -0
- package/dist/bridge/signal-bridge.d.ts +46 -0
- package/dist/bridge/signal-bridge.d.ts.map +1 -0
- package/dist/bridge/signal-bridge.js +75 -0
- package/dist/bridge/signal-bridge.js.map +1 -0
- package/dist/core/capability-registry.d.ts +16 -0
- package/dist/core/capability-registry.d.ts.map +1 -0
- package/dist/core/capability-registry.js +71 -0
- package/dist/core/capability-registry.js.map +1 -0
- package/dist/core/clock.d.ts +17 -0
- package/dist/core/clock.d.ts.map +1 -0
- package/dist/core/clock.js +63 -0
- package/dist/core/clock.js.map +1 -0
- package/dist/core/mission.d.ts +4 -0
- package/dist/core/mission.d.ts.map +1 -0
- package/dist/core/mission.js +74 -0
- package/dist/core/mission.js.map +1 -0
- package/dist/core/organism-context.d.ts +139 -0
- package/dist/core/organism-context.d.ts.map +1 -0
- package/dist/core/organism-context.js +62 -0
- package/dist/core/organism-context.js.map +1 -0
- package/dist/core/organism-runtime.d.ts +199 -0
- package/dist/core/organism-runtime.d.ts.map +1 -0
- package/dist/core/organism-runtime.js +1016 -0
- package/dist/core/organism-runtime.js.map +1 -0
- package/dist/decorators/index.d.ts +39 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +165 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/economy/market-engine.d.ts +57 -0
- package/dist/economy/market-engine.d.ts.map +1 -0
- package/dist/economy/market-engine.js +258 -0
- package/dist/economy/market-engine.js.map +1 -0
- package/dist/economy/resource-allocator.d.ts +39 -0
- package/dist/economy/resource-allocator.d.ts.map +1 -0
- package/dist/economy/resource-allocator.js +153 -0
- package/dist/economy/resource-allocator.js.map +1 -0
- package/dist/economy/utility-engine.d.ts +16 -0
- package/dist/economy/utility-engine.d.ts.map +1 -0
- package/dist/economy/utility-engine.js +80 -0
- package/dist/economy/utility-engine.js.map +1 -0
- package/dist/economy/utility-forecaster.d.ts +24 -0
- package/dist/economy/utility-forecaster.d.ts.map +1 -0
- package/dist/economy/utility-forecaster.js +60 -0
- package/dist/economy/utility-forecaster.js.map +1 -0
- package/dist/errors/organism.errors.d.ts +23 -0
- package/dist/errors/organism.errors.d.ts.map +1 -0
- package/dist/errors/organism.errors.js +50 -0
- package/dist/errors/organism.errors.js.map +1 -0
- package/dist/events/organism-events.d.ts +61 -0
- package/dist/events/organism-events.d.ts.map +1 -0
- package/dist/events/organism-events.js +95 -0
- package/dist/events/organism-events.js.map +1 -0
- package/dist/evolution/evolution-engine.d.ts +41 -0
- package/dist/evolution/evolution-engine.d.ts.map +1 -0
- package/dist/evolution/evolution-engine.js +135 -0
- package/dist/evolution/evolution-engine.js.map +1 -0
- package/dist/evolution/mutation-engine.d.ts +21 -0
- package/dist/evolution/mutation-engine.d.ts.map +1 -0
- package/dist/evolution/mutation-engine.js +84 -0
- package/dist/evolution/mutation-engine.js.map +1 -0
- package/dist/genealogy/genealogy-manager.d.ts +18 -0
- package/dist/genealogy/genealogy-manager.d.ts.map +1 -0
- package/dist/genealogy/genealogy-manager.js +64 -0
- package/dist/genealogy/genealogy-manager.js.map +1 -0
- package/dist/governance/constitution.d.ts +20 -0
- package/dist/governance/constitution.d.ts.map +1 -0
- package/dist/governance/constitution.js +109 -0
- package/dist/governance/constitution.js.map +1 -0
- package/dist/host/organism-host-registry.d.ts +24 -0
- package/dist/host/organism-host-registry.d.ts.map +1 -0
- package/dist/host/organism-host-registry.js +65 -0
- package/dist/host/organism-host-registry.js.map +1 -0
- package/dist/host/organism-host.d.ts +32 -0
- package/dist/host/organism-host.d.ts.map +1 -0
- package/dist/host/organism-host.js +64 -0
- package/dist/host/organism-host.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +117 -0
- package/dist/index.js.map +1 -0
- package/dist/integration/create-ops-organism.d.ts +34 -0
- package/dist/integration/create-ops-organism.d.ts.map +1 -0
- package/dist/integration/create-ops-organism.js +43 -0
- package/dist/integration/create-ops-organism.js.map +1 -0
- package/dist/lifecycle/birth-engine.d.ts +41 -0
- package/dist/lifecycle/birth-engine.d.ts.map +1 -0
- package/dist/lifecycle/birth-engine.js +182 -0
- package/dist/lifecycle/birth-engine.js.map +1 -0
- package/dist/lifecycle/decision-engine.d.ts +19 -0
- package/dist/lifecycle/decision-engine.d.ts.map +1 -0
- package/dist/lifecycle/decision-engine.js +137 -0
- package/dist/lifecycle/decision-engine.js.map +1 -0
- package/dist/lifecycle/reproduction-engine.d.ts +58 -0
- package/dist/lifecycle/reproduction-engine.d.ts.map +1 -0
- package/dist/lifecycle/reproduction-engine.js +207 -0
- package/dist/lifecycle/reproduction-engine.js.map +1 -0
- package/dist/lifecycle/survival-engine.d.ts +17 -0
- package/dist/lifecycle/survival-engine.d.ts.map +1 -0
- package/dist/lifecycle/survival-engine.js +83 -0
- package/dist/lifecycle/survival-engine.js.map +1 -0
- package/dist/observability/metrics.d.ts +37 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +80 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/perception/perception-engine.d.ts +40 -0
- package/dist/perception/perception-engine.d.ts.map +1 -0
- package/dist/perception/perception-engine.js +126 -0
- package/dist/perception/perception-engine.js.map +1 -0
- package/dist/persistence/in-memory-organism-repository.d.ts +2 -0
- package/dist/persistence/in-memory-organism-repository.d.ts.map +1 -0
- package/dist/persistence/in-memory-organism-repository.js +18 -0
- package/dist/persistence/in-memory-organism-repository.js.map +1 -0
- package/dist/persistence/organism-repository.d.ts +42 -0
- package/dist/persistence/organism-repository.d.ts.map +1 -0
- package/dist/persistence/organism-repository.js +105 -0
- package/dist/persistence/organism-repository.js.map +1 -0
- package/dist/types/organism.types.d.ts +482 -0
- package/dist/types/organism.types.d.ts.map +1 -0
- package/dist/types/organism.types.js +45 -0
- package/dist/types/organism.types.js.map +1 -0
- package/examples/ecommerce-organism/run.ts +245 -0
- package/package.json +73 -0
- package/src/bridge/signal-bridge.ts +116 -0
- package/src/core/capability-registry.ts +72 -0
- package/src/core/clock.ts +58 -0
- package/src/core/mission.ts +83 -0
- package/src/core/organism-context.ts +176 -0
- package/src/core/organism-runtime.ts +1369 -0
- package/src/decorators/index.ts +180 -0
- package/src/economy/market-engine.ts +324 -0
- package/src/economy/resource-allocator.ts +188 -0
- package/src/economy/utility-engine.ts +103 -0
- package/src/economy/utility-forecaster.ts +88 -0
- package/src/errors/organism.errors.ts +47 -0
- package/src/events/organism-events.ts +122 -0
- package/src/evolution/evolution-engine.ts +167 -0
- package/src/evolution/mutation-engine.ts +110 -0
- package/src/genealogy/genealogy-manager.ts +70 -0
- package/src/governance/constitution.ts +120 -0
- package/src/host/organism-host-registry.ts +72 -0
- package/src/host/organism-host.ts +103 -0
- package/src/index.ts +78 -0
- package/src/integration/create-ops-organism.ts +80 -0
- package/src/lifecycle/birth-engine.ts +225 -0
- package/src/lifecycle/decision-engine.ts +158 -0
- package/src/lifecycle/reproduction-engine.ts +289 -0
- package/src/lifecycle/survival-engine.ts +95 -0
- package/src/observability/metrics.ts +120 -0
- package/src/perception/perception-engine.ts +140 -0
- package/src/persistence/in-memory-organism-repository.ts +1 -0
- package/src/persistence/organism-repository.ts +134 -0
- package/src/types/organism.types.ts +591 -0
- package/tsconfig.jest.json +8 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AgentMutation,
|
|
3
|
+
AgentOutcomeReport,
|
|
4
|
+
AgentResourceWallet,
|
|
5
|
+
ConstitutionDefinition,
|
|
6
|
+
InheritancePolicy,
|
|
7
|
+
MissionDefinition,
|
|
8
|
+
NegotiationResult,
|
|
9
|
+
OrganismDecision,
|
|
10
|
+
ReproduceRequest,
|
|
11
|
+
ResourceBid,
|
|
12
|
+
ResourceRequest,
|
|
13
|
+
RuntimeAgentRecord,
|
|
14
|
+
UtilityForecast,
|
|
15
|
+
} from '../types/organism.types';
|
|
16
|
+
import { OrganismError } from '../errors/organism.errors';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Controlled context exposed to agents — not full organism internals.
|
|
20
|
+
*/
|
|
21
|
+
export class OrganismAgentContext {
|
|
22
|
+
constructor(
|
|
23
|
+
private readonly api: {
|
|
24
|
+
getMission: () => MissionDefinition;
|
|
25
|
+
getConstitution: () => ConstitutionDefinition | undefined;
|
|
26
|
+
getWallet: () => AgentResourceWallet;
|
|
27
|
+
findAgents: (query: { capabilities?: string[] }) => Promise<RuntimeAgentRecord[]>;
|
|
28
|
+
delegate: (input: { to: string; task: string }) => Promise<{ ok: boolean; result?: string }>;
|
|
29
|
+
requestResources: (input: {
|
|
30
|
+
reason: string;
|
|
31
|
+
requested: ResourceRequest;
|
|
32
|
+
expectedValue?: number;
|
|
33
|
+
confidence?: number;
|
|
34
|
+
urgency?: number;
|
|
35
|
+
useMarket?: boolean;
|
|
36
|
+
}) => Promise<{
|
|
37
|
+
approved: boolean;
|
|
38
|
+
reason: string;
|
|
39
|
+
wallet?: AgentResourceWallet;
|
|
40
|
+
forecast?: UtilityForecast;
|
|
41
|
+
}>;
|
|
42
|
+
placeBid?: (input: {
|
|
43
|
+
reason: string;
|
|
44
|
+
requested: ResourceRequest;
|
|
45
|
+
expectedValue: number;
|
|
46
|
+
confidence: number;
|
|
47
|
+
urgency?: number;
|
|
48
|
+
bidPrice?: number;
|
|
49
|
+
}) => ResourceBid;
|
|
50
|
+
negotiate?: (input: {
|
|
51
|
+
toAgentId: string;
|
|
52
|
+
reason: string;
|
|
53
|
+
transfer: ResourceRequest;
|
|
54
|
+
expectedValue?: number;
|
|
55
|
+
confidence?: number;
|
|
56
|
+
}) => Promise<NegotiationResult>;
|
|
57
|
+
reportOutcome: (report: AgentOutcomeReport) => Promise<void>;
|
|
58
|
+
requestApproval: (input: {
|
|
59
|
+
action: string;
|
|
60
|
+
reason: string;
|
|
61
|
+
risk?: number;
|
|
62
|
+
expectedValue?: number;
|
|
63
|
+
}) => Promise<{ approved: boolean; reason: string }>;
|
|
64
|
+
spawn: (input: {
|
|
65
|
+
reason: string;
|
|
66
|
+
objective: string;
|
|
67
|
+
needId: string;
|
|
68
|
+
requiredCapabilities: string[];
|
|
69
|
+
specialize?: string[];
|
|
70
|
+
tokens?: number;
|
|
71
|
+
}) => Promise<RuntimeAgentRecord>;
|
|
72
|
+
reproduce: (request: ReproduceRequest) => Promise<RuntimeAgentRecord>;
|
|
73
|
+
mutate?: (input: { reason: string; mutation: AgentMutation }) => Promise<RuntimeAgentRecord>;
|
|
74
|
+
}
|
|
75
|
+
) {}
|
|
76
|
+
|
|
77
|
+
get mission(): MissionDefinition {
|
|
78
|
+
return this.api.getMission();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get constitution(): ConstitutionDefinition | undefined {
|
|
82
|
+
return this.api.getConstitution();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get resources(): AgentResourceWallet {
|
|
86
|
+
return this.api.getWallet();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
findAgents(query: { capabilities?: string[] }): Promise<RuntimeAgentRecord[]> {
|
|
90
|
+
return this.api.findAgents(query);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
delegate(input: { to: string; task: string }): Promise<{ ok: boolean; result?: string }> {
|
|
94
|
+
return this.api.delegate(input);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
requestResources(input: {
|
|
98
|
+
reason: string;
|
|
99
|
+
requested: ResourceRequest;
|
|
100
|
+
expectedValue?: number;
|
|
101
|
+
confidence?: number;
|
|
102
|
+
urgency?: number;
|
|
103
|
+
useMarket?: boolean;
|
|
104
|
+
}): Promise<{
|
|
105
|
+
approved: boolean;
|
|
106
|
+
reason: string;
|
|
107
|
+
wallet?: AgentResourceWallet;
|
|
108
|
+
forecast?: UtilityForecast;
|
|
109
|
+
}> {
|
|
110
|
+
return this.api.requestResources(input);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
placeBid(input: {
|
|
114
|
+
reason: string;
|
|
115
|
+
requested: ResourceRequest;
|
|
116
|
+
expectedValue: number;
|
|
117
|
+
confidence: number;
|
|
118
|
+
urgency?: number;
|
|
119
|
+
bidPrice?: number;
|
|
120
|
+
}): ResourceBid {
|
|
121
|
+
if (!this.api.placeBid) {
|
|
122
|
+
throw new OrganismError('Bidding is not enabled on this context', 'NOT_IMPLEMENTED');
|
|
123
|
+
}
|
|
124
|
+
return this.api.placeBid(input);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
negotiate(input: {
|
|
128
|
+
toAgentId: string;
|
|
129
|
+
reason: string;
|
|
130
|
+
transfer: ResourceRequest;
|
|
131
|
+
expectedValue?: number;
|
|
132
|
+
confidence?: number;
|
|
133
|
+
}): Promise<NegotiationResult> {
|
|
134
|
+
if (!this.api.negotiate) {
|
|
135
|
+
throw new OrganismError('Negotiation is not enabled on this context', 'NOT_IMPLEMENTED');
|
|
136
|
+
}
|
|
137
|
+
return this.api.negotiate(input);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
reportOutcome(report: AgentOutcomeReport): Promise<void> {
|
|
141
|
+
return this.api.reportOutcome(report);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
requestApproval(input: {
|
|
145
|
+
action: string;
|
|
146
|
+
reason: string;
|
|
147
|
+
risk?: number;
|
|
148
|
+
expectedValue?: number;
|
|
149
|
+
}): Promise<{ approved: boolean; reason: string }> {
|
|
150
|
+
return this.api.requestApproval(input);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
spawn(input: {
|
|
154
|
+
reason: string;
|
|
155
|
+
objective: string;
|
|
156
|
+
needId: string;
|
|
157
|
+
requiredCapabilities: string[];
|
|
158
|
+
specialize?: string[];
|
|
159
|
+
tokens?: number;
|
|
160
|
+
}): Promise<RuntimeAgentRecord> {
|
|
161
|
+
return this.api.spawn(input);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
reproduce(request: ReproduceRequest): Promise<RuntimeAgentRecord> {
|
|
165
|
+
return this.api.reproduce(request);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
mutate(input: { reason: string; mutation: AgentMutation }): Promise<RuntimeAgentRecord> {
|
|
169
|
+
if (!this.api.mutate) {
|
|
170
|
+
throw new OrganismError('Mutation is not enabled on this context', 'NOT_IMPLEMENTED');
|
|
171
|
+
}
|
|
172
|
+
return this.api.mutate(input);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export type { OrganismDecision, InheritancePolicy, ReproduceRequest };
|