@dudousxd/nestjs-agent 1.9.0 → 1.11.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/README.md +159 -34
- package/dist/{agent-deps.factory-DuTy1UyU.d.cts → agent-deps.factory-BRTBu0lV.d.cts} +25 -21
- package/dist/{agent-deps.factory-DuTy1UyU.d.ts → agent-deps.factory-BRTBu0lV.d.ts} +25 -21
- package/dist/durable/index.cjs +153 -23
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.d.cts +1 -1
- package/dist/durable/index.d.ts +1 -1
- package/dist/durable/index.js +156 -26
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +219 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +100 -11
- package/dist/index.d.ts +100 -11
- package/dist/index.js +218 -27
- package/dist/index.js.map +1 -1
- package/dist/media/index.cjs +641 -0
- package/dist/media/index.cjs.map +1 -0
- package/dist/media/index.d.cts +238 -0
- package/dist/media/index.d.ts +238 -0
- package/dist/media/index.js +608 -0
- package/dist/media/index.js.map +1 -0
- package/package.json +20 -3
package/dist/durable/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AgentStore, AgentRunInput, AgentLoopResult, LlmStepEnvelope, BufferedModelTurnResult, ToolStepEnvelope, AgentRunner, TokenStreamSink, HumanReply } from '@dudousxd/nestjs-agent-core';
|
|
2
2
|
import { RunGateway, WorkflowCtx } from '@dudousxd/nestjs-durable-core';
|
|
3
|
-
import { A as AgentDepsFactory, a as AgentSurface, b as AgentModuleOptions } from '../agent-deps.factory-
|
|
3
|
+
import { A as AgentDepsFactory, a as AgentSurface, b as AgentModuleOptions } from '../agent-deps.factory-BRTBu0lV.cjs';
|
|
4
4
|
import { WorkflowService } from '@dudousxd/nestjs-durable';
|
|
5
5
|
import { DynamicModule } from '@nestjs/common';
|
|
6
6
|
import '@standard-schema/spec';
|
package/dist/durable/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AgentStore, AgentRunInput, AgentLoopResult, LlmStepEnvelope, BufferedModelTurnResult, ToolStepEnvelope, AgentRunner, TokenStreamSink, HumanReply } from '@dudousxd/nestjs-agent-core';
|
|
2
2
|
import { RunGateway, WorkflowCtx } from '@dudousxd/nestjs-durable-core';
|
|
3
|
-
import { A as AgentDepsFactory, a as AgentSurface, b as AgentModuleOptions } from '../agent-deps.factory-
|
|
3
|
+
import { A as AgentDepsFactory, a as AgentSurface, b as AgentModuleOptions } from '../agent-deps.factory-BRTBu0lV.js';
|
|
4
4
|
import { WorkflowService } from '@dudousxd/nestjs-durable';
|
|
5
5
|
import { DynamicModule } from '@nestjs/common';
|
|
6
6
|
import '@standard-schema/spec';
|
package/dist/durable/index.js
CHANGED
|
@@ -800,9 +800,9 @@ AgentDurableModule = _ts_decorate4([
|
|
|
800
800
|
], AgentDurableModule);
|
|
801
801
|
|
|
802
802
|
// src/agent.module.ts
|
|
803
|
-
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER11, AGENT_APPROVAL_PORT, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY7, AGENT_DURABLE_RUNNER as AGENT_DURABLE_RUNNER2, AGENT_MEMORY as AGENT_MEMORY3, AGENT_MODEL as AGENT_MODEL2, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG2, AGENT_OPTIONS as AGENT_OPTIONS5, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER2, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE3, AGENT_REGISTRY as AGENT_REGISTRY6, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK3, AGENT_SKILLS as AGENT_SKILLS3, AGENT_SKILL_SOURCES as AGENT_SKILL_SOURCES2, AGENT_STORE as AGENT_STORE6, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry6, DefaultRolesPolicy, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
|
|
804
|
-
import { Global as Global2, Module as Module2 } from "@nestjs/common";
|
|
805
|
-
import { DiscoveryModule, RouterModule } from "@nestjs/core";
|
|
803
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER11, AGENT_APPROVAL_PORT, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY7, AGENT_DURABLE_RUNNER as AGENT_DURABLE_RUNNER2, AGENT_MEMORY as AGENT_MEMORY3, AGENT_MODEL as AGENT_MODEL2, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG2, AGENT_OPTIONS as AGENT_OPTIONS5, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER2, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE3, AGENT_REGISTRY as AGENT_REGISTRY6, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK3, AGENT_SKILLS as AGENT_SKILLS3, AGENT_SKILL_SOURCES as AGENT_SKILL_SOURCES2, AGENT_STORE as AGENT_STORE6, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry6, DefaultRolesPolicy, InMemoryAgentStore, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
|
|
804
|
+
import { Global as Global2, Logger as Logger6, Module as Module2 } from "@nestjs/common";
|
|
805
|
+
import { DiscoveryModule, ModulesContainer, RouterModule } from "@nestjs/core";
|
|
806
806
|
|
|
807
807
|
// src/agent-deps.factory.ts
|
|
808
808
|
import { AGENT_MEMORY, AGENT_MODEL, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_ROLES_POLICY, AGENT_SINK as AGENT_SINK2, AGENT_SKILLS, AGENT_STORE as AGENT_STORE3, AGENT_TOOL_REGISTRY, AgentRegistry as AgentRegistry2, ToolRegistry as ToolRegistry2, normalizeDelegation, summarizeWithModel, windowHistory } from "@dudousxd/nestjs-agent-core";
|
|
@@ -925,7 +925,7 @@ var AgentDepsFactory2 = class {
|
|
|
925
925
|
} : {},
|
|
926
926
|
registry: this.registry,
|
|
927
927
|
promptContributors: this.promptContributors,
|
|
928
|
-
systemPrompt: definition?.systemPrompt ?? "You are a helpful assistant.",
|
|
928
|
+
systemPrompt: definition?.systemPrompt ?? this.options.systemPrompt ?? "You are a helpful assistant.",
|
|
929
929
|
maxSteps: definition?.maxSteps ?? 8,
|
|
930
930
|
...definition?.maxDelegationDepth !== void 0 ? {
|
|
931
931
|
maxDelegationDepth: definition.maxDelegationDepth
|
|
@@ -3794,6 +3794,93 @@ var LedgerQuotaStore = class {
|
|
|
3794
3794
|
}
|
|
3795
3795
|
};
|
|
3796
3796
|
|
|
3797
|
+
// src/resolver/anonymous-actor-resolver.ts
|
|
3798
|
+
import { createHash, randomBytes } from "crypto";
|
|
3799
|
+
var TOKEN_PATTERN = /^[A-Za-z0-9_-]{43}$/;
|
|
3800
|
+
var MINTED = /* @__PURE__ */ Symbol("nestjs-agent:anonymous-token");
|
|
3801
|
+
function readCookie(req, name) {
|
|
3802
|
+
const header = req.headers?.cookie;
|
|
3803
|
+
const raw = Array.isArray(header) ? header.join("; ") : header;
|
|
3804
|
+
if (raw === void 0) return void 0;
|
|
3805
|
+
for (const pair of raw.split(";")) {
|
|
3806
|
+
const index = pair.indexOf("=");
|
|
3807
|
+
if (index === -1) continue;
|
|
3808
|
+
if (pair.slice(0, index).trim() === name) {
|
|
3809
|
+
try {
|
|
3810
|
+
return decodeURIComponent(pair.slice(index + 1).trim());
|
|
3811
|
+
} catch {
|
|
3812
|
+
return void 0;
|
|
3813
|
+
}
|
|
3814
|
+
}
|
|
3815
|
+
}
|
|
3816
|
+
return void 0;
|
|
3817
|
+
}
|
|
3818
|
+
__name(readCookie, "readCookie");
|
|
3819
|
+
function isHttps(req) {
|
|
3820
|
+
if (req.secure === true) return true;
|
|
3821
|
+
const forwarded = req.headers?.["x-forwarded-proto"];
|
|
3822
|
+
const proto = Array.isArray(forwarded) ? forwarded[0] : forwarded;
|
|
3823
|
+
return proto?.split(",")[0]?.trim() === "https";
|
|
3824
|
+
}
|
|
3825
|
+
__name(isHttps, "isHttps");
|
|
3826
|
+
var AnonymousActorResolver = class {
|
|
3827
|
+
static {
|
|
3828
|
+
__name(this, "AnonymousActorResolver");
|
|
3829
|
+
}
|
|
3830
|
+
options;
|
|
3831
|
+
cookieName;
|
|
3832
|
+
roles;
|
|
3833
|
+
constructor(options = {}) {
|
|
3834
|
+
this.options = options;
|
|
3835
|
+
this.cookieName = options.cookieName ?? "agent_anon";
|
|
3836
|
+
this.roles = options.roles ?? [
|
|
3837
|
+
"anonymous"
|
|
3838
|
+
];
|
|
3839
|
+
}
|
|
3840
|
+
resolve(request) {
|
|
3841
|
+
const req = typeof request === "object" && request !== null ? request : {};
|
|
3842
|
+
let token = req[MINTED] ?? readCookie(req, this.cookieName);
|
|
3843
|
+
if (token === void 0 || !TOKEN_PATTERN.test(token)) {
|
|
3844
|
+
token = randomBytes(32).toString("base64url");
|
|
3845
|
+
req[MINTED] = token;
|
|
3846
|
+
this.setCookie(req, token);
|
|
3847
|
+
}
|
|
3848
|
+
const digest = createHash("sha256").update(token).digest("base64url").slice(0, 32);
|
|
3849
|
+
return {
|
|
3850
|
+
id: `anon:${digest}`,
|
|
3851
|
+
roles: [
|
|
3852
|
+
...this.roles
|
|
3853
|
+
]
|
|
3854
|
+
};
|
|
3855
|
+
}
|
|
3856
|
+
setCookie(req, token) {
|
|
3857
|
+
const res = req.res;
|
|
3858
|
+
if (res?.setHeader === void 0 || res.headersSent === true) return;
|
|
3859
|
+
const sameSite = this.options.sameSite ?? "lax";
|
|
3860
|
+
const secureOption = this.options.secure ?? "auto";
|
|
3861
|
+
const secure = sameSite === "none" || (secureOption === "auto" ? isHttps(req) : secureOption);
|
|
3862
|
+
const maxAge = Math.round((this.options.maxAgeDays ?? 365) * 24 * 60 * 60);
|
|
3863
|
+
const cookie = [
|
|
3864
|
+
`${this.cookieName}=${token}`,
|
|
3865
|
+
`Path=${this.options.path ?? "/"}`,
|
|
3866
|
+
`Max-Age=${maxAge}`,
|
|
3867
|
+
"HttpOnly",
|
|
3868
|
+
`SameSite=${sameSite === "none" ? "None" : sameSite === "strict" ? "Strict" : "Lax"}`,
|
|
3869
|
+
...secure ? [
|
|
3870
|
+
"Secure"
|
|
3871
|
+
] : []
|
|
3872
|
+
].join("; ");
|
|
3873
|
+
const existing = res.getHeader?.("Set-Cookie");
|
|
3874
|
+
const list = Array.isArray(existing) ? existing.map(String) : existing !== void 0 ? [
|
|
3875
|
+
String(existing)
|
|
3876
|
+
] : [];
|
|
3877
|
+
res.setHeader("Set-Cookie", [
|
|
3878
|
+
...list,
|
|
3879
|
+
cookie
|
|
3880
|
+
]);
|
|
3881
|
+
}
|
|
3882
|
+
};
|
|
3883
|
+
|
|
3797
3884
|
// src/runner/inline-agent-runner.ts
|
|
3798
3885
|
import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY6, AGENT_STORE as AGENT_STORE5, RunCancelledError as RunCancelledError2, agentFailureCode as agentFailureCode2, encodeStreamEvent as encodeStreamEvent3, publishAgentRunFailed as publishAgentRunFailed2, runAgentLoop as runAgentLoop2, settleAll as settleAll2, settleUnsettledDelegation as settleUnsettledDelegation2 } from "@dudousxd/nestjs-agent-core";
|
|
3799
3886
|
import { Inject as Inject20, Injectable as Injectable10, Logger as Logger5 } from "@nestjs/common";
|
|
@@ -4268,7 +4355,51 @@ function _ts_decorate23(decorators, target, key, desc) {
|
|
|
4268
4355
|
}
|
|
4269
4356
|
__name(_ts_decorate23, "_ts_decorate");
|
|
4270
4357
|
var DEFAULT_PATH = "agent";
|
|
4271
|
-
|
|
4358
|
+
var logger = new Logger6("AgentModule");
|
|
4359
|
+
function externalStoreWrapper(modules) {
|
|
4360
|
+
for (const module of modules.values()) {
|
|
4361
|
+
if (module.metatype === AgentModule) continue;
|
|
4362
|
+
const wrapper = module.providers.get(AGENT_STORE6);
|
|
4363
|
+
if (wrapper !== void 0) return wrapper;
|
|
4364
|
+
}
|
|
4365
|
+
return void 0;
|
|
4366
|
+
}
|
|
4367
|
+
__name(externalStoreWrapper, "externalStoreWrapper");
|
|
4368
|
+
function forwardingStore(wrapper) {
|
|
4369
|
+
const target = /* @__PURE__ */ __name(() => {
|
|
4370
|
+
const instance = wrapper.instance;
|
|
4371
|
+
if (instance === void 0 || instance === null) {
|
|
4372
|
+
throw new Error("AgentModule: the AGENT_STORE bound by another module is not ready yet");
|
|
4373
|
+
}
|
|
4374
|
+
return instance;
|
|
4375
|
+
}, "target");
|
|
4376
|
+
return new Proxy({}, {
|
|
4377
|
+
get(_, property) {
|
|
4378
|
+
const store = target();
|
|
4379
|
+
const value = store[property];
|
|
4380
|
+
return typeof value === "function" ? value.bind(store) : value;
|
|
4381
|
+
},
|
|
4382
|
+
has(_, property) {
|
|
4383
|
+
return property in target();
|
|
4384
|
+
}
|
|
4385
|
+
});
|
|
4386
|
+
}
|
|
4387
|
+
__name(forwardingStore, "forwardingStore");
|
|
4388
|
+
function resolveStore(options, modules) {
|
|
4389
|
+
if (options.store !== void 0) return options.store;
|
|
4390
|
+
const external = externalStoreWrapper(modules);
|
|
4391
|
+
if (external !== void 0) return forwardingStore(external);
|
|
4392
|
+
logger.warn("No `store` configured and no store module imported \u2014 using the in-memory store. Threads are lost on restart and not shared between processes: not for production. Pass `store`, or import a store module (e.g. MikroOrmAgentStoreModule.forFeature()).");
|
|
4393
|
+
return new InMemoryAgentStore();
|
|
4394
|
+
}
|
|
4395
|
+
__name(resolveStore, "resolveStore");
|
|
4396
|
+
function resolveCatalog(options) {
|
|
4397
|
+
if (options.models !== void 0) return options.models;
|
|
4398
|
+
const carried = options.model.catalog;
|
|
4399
|
+
return carried !== void 0 && typeof carried.list === "function" ? carried : void 0;
|
|
4400
|
+
}
|
|
4401
|
+
__name(resolveCatalog, "resolveCatalog");
|
|
4402
|
+
function sharedProviders(durable) {
|
|
4272
4403
|
const providers = [
|
|
4273
4404
|
{
|
|
4274
4405
|
provide: AGENT_TOOL_REGISTRY3,
|
|
@@ -4326,7 +4457,11 @@ function sharedProviders(durable, includeStore) {
|
|
|
4326
4457
|
},
|
|
4327
4458
|
{
|
|
4328
4459
|
provide: AGENT_ACTOR_RESOLVER11,
|
|
4329
|
-
useFactory: /* @__PURE__ */ __name((options) =>
|
|
4460
|
+
useFactory: /* @__PURE__ */ __name((options) => {
|
|
4461
|
+
if (options.actorResolver !== void 0) return options.actorResolver;
|
|
4462
|
+
logger.warn("No `actorResolver` configured \u2014 the agent endpoints are PUBLIC: every browser gets its own anonymous identity (an HttpOnly cookie). Set `actorResolver: requestUserActorResolver()` (or your own) to require login.");
|
|
4463
|
+
return new AnonymousActorResolver();
|
|
4464
|
+
}, "useFactory"),
|
|
4330
4465
|
inject: [
|
|
4331
4466
|
AGENT_OPTIONS5
|
|
4332
4467
|
]
|
|
@@ -4360,7 +4495,7 @@ function sharedProviders(durable, includeStore) {
|
|
|
4360
4495
|
},
|
|
4361
4496
|
{
|
|
4362
4497
|
provide: AGENT_MODEL_CATALOG2,
|
|
4363
|
-
useFactory: /* @__PURE__ */ __name((o) => o
|
|
4498
|
+
useFactory: /* @__PURE__ */ __name((o) => resolveCatalog(o), "useFactory"),
|
|
4364
4499
|
inject: [
|
|
4365
4500
|
AGENT_OPTIONS5
|
|
4366
4501
|
]
|
|
@@ -4385,15 +4520,14 @@ function sharedProviders(durable, includeStore) {
|
|
|
4385
4520
|
useExisting: AgentApprovalPortAdapter
|
|
4386
4521
|
}
|
|
4387
4522
|
];
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
}
|
|
4523
|
+
providers.push({
|
|
4524
|
+
provide: AGENT_STORE6,
|
|
4525
|
+
useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
|
|
4526
|
+
inject: [
|
|
4527
|
+
AGENT_OPTIONS5,
|
|
4528
|
+
ModulesContainer
|
|
4529
|
+
]
|
|
4530
|
+
});
|
|
4397
4531
|
if (durable) {
|
|
4398
4532
|
providers.push({
|
|
4399
4533
|
provide: AGENT_RUNNER2,
|
|
@@ -4419,7 +4553,7 @@ function sharedProviders(durable, includeStore) {
|
|
|
4419
4553
|
return providers;
|
|
4420
4554
|
}
|
|
4421
4555
|
__name(sharedProviders, "sharedProviders");
|
|
4422
|
-
function exportsFor(
|
|
4556
|
+
function exportsFor() {
|
|
4423
4557
|
return [
|
|
4424
4558
|
AGENT_OPTIONS5,
|
|
4425
4559
|
AGENT_TOOL_REGISTRY3,
|
|
@@ -4428,9 +4562,7 @@ function exportsFor(includeStore) {
|
|
|
4428
4562
|
AGENT_ROLES_POLICY2,
|
|
4429
4563
|
AGENT_ACTOR_RESOLVER11,
|
|
4430
4564
|
AGENT_MODEL2,
|
|
4431
|
-
|
|
4432
|
-
AGENT_STORE6
|
|
4433
|
-
] : [],
|
|
4565
|
+
AGENT_STORE6,
|
|
4434
4566
|
AGENT_QUOTA_STORE3,
|
|
4435
4567
|
AGENT_MODEL_CATALOG2,
|
|
4436
4568
|
AGENT_QUOTA_PROVIDER2,
|
|
@@ -4501,7 +4633,6 @@ var AgentModule = class _AgentModule {
|
|
|
4501
4633
|
}
|
|
4502
4634
|
static forRoot(options) {
|
|
4503
4635
|
const path = options.path ?? DEFAULT_PATH;
|
|
4504
|
-
const includeStore = options.store !== void 0;
|
|
4505
4636
|
applyGuards(options.guards);
|
|
4506
4637
|
return {
|
|
4507
4638
|
module: _AgentModule,
|
|
@@ -4516,15 +4647,14 @@ var AgentModule = class _AgentModule {
|
|
|
4516
4647
|
provide: AGENT_OPTIONS5,
|
|
4517
4648
|
useValue: options
|
|
4518
4649
|
},
|
|
4519
|
-
...sharedProviders(options.durable ?? false
|
|
4650
|
+
...sharedProviders(options.durable ?? false),
|
|
4520
4651
|
...guardProviders(options.guards)
|
|
4521
4652
|
],
|
|
4522
|
-
exports: exportsFor(
|
|
4653
|
+
exports: exportsFor()
|
|
4523
4654
|
};
|
|
4524
4655
|
}
|
|
4525
4656
|
static forRootAsync(options) {
|
|
4526
4657
|
const path = options.path ?? DEFAULT_PATH;
|
|
4527
|
-
const includeStore = options.externalStore !== true;
|
|
4528
4658
|
applyGuards(options.guards);
|
|
4529
4659
|
return {
|
|
4530
4660
|
module: _AgentModule,
|
|
@@ -4551,10 +4681,10 @@ var AgentModule = class _AgentModule {
|
|
|
4551
4681
|
}), "useFactory"),
|
|
4552
4682
|
inject: options.inject ?? []
|
|
4553
4683
|
},
|
|
4554
|
-
...sharedProviders(options.durable ?? false
|
|
4684
|
+
...sharedProviders(options.durable ?? false),
|
|
4555
4685
|
...guardProviders(options.guards)
|
|
4556
4686
|
],
|
|
4557
|
-
exports: exportsFor(
|
|
4687
|
+
exports: exportsFor()
|
|
4558
4688
|
};
|
|
4559
4689
|
}
|
|
4560
4690
|
};
|