@economic/agents 2.11.0 → 2.11.1
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 +1 -1
- package/dist/index.d.mts +11 -9
- package/dist/index.mjs +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -663,7 +663,7 @@ Imported from `@economic/agents` unless noted.
|
|
|
663
663
|
| Export | Description |
|
|
664
664
|
| ------------------------------------------------------------------------ | -------------------------------------------------------------------------- |
|
|
665
665
|
| `tool(def)` / `Tool` / `ToolSet` | Define a tool with optional `approval`, `authorize`, and `onUnauthorized`. |
|
|
666
|
-
| `action(def)` / `Action` / `
|
|
666
|
+
| `action(def)` / `Action` / `RegisteredAction` / `ActionContext` | Define a ledger-backed action with approval and idempotency support. |
|
|
667
667
|
| `skill(def)` / `Skill` | Define a skill with optional `tools`, `actions`, and authorization. |
|
|
668
668
|
| `ToolContext` | `RequestContext & { _userContext?: UserContext }`. |
|
|
669
669
|
| `AgentEnv` | The bindings the runtime expects. |
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Agent as Agent$1, AgentOptions, Connection, ConnectionContext, SubAgentClass } from "agents";
|
|
2
|
-
import { Action as Action$1, ActionConfig
|
|
3
|
-
import { FlexibleSchema,
|
|
2
|
+
import { Action as Action$1, ActionConfig, ActionContext as ActionContext$1, ChatResponseResult, PrepareStepContext, Session, Think, ToolCallContext, ToolCallDecision, TurnConfig, TurnContext, skills } from "@cloudflare/think";
|
|
3
|
+
import { FlexibleSchema, JSONValue, LanguageModel, ModelMessage, Tool as Tool$1, ToolExecutionOptions, UIMessage } from "ai";
|
|
4
4
|
import { Observability } from "agents/observability";
|
|
5
5
|
import { createCompactFunction } from "agents/experimental/memory/utils";
|
|
6
6
|
import { SkillSource as SkillSource$1 } from "agents/skills";
|
|
@@ -415,17 +415,19 @@ type ActionContext<Context extends Record<string, unknown> = Record<string, unkn
|
|
|
415
415
|
experimental_context: Context; /** The action's resolved domain key, or its tool-call fallback when none was declared. */
|
|
416
416
|
idempotencyKey: string;
|
|
417
417
|
};
|
|
418
|
-
type
|
|
418
|
+
type Action<Context extends Record<string, unknown> = Record<string, unknown>, Input = any, Output = any> = Omit<Tool<Context, Input, Output>, "approval" | "description" | "execute" | "inputSchema" | "needsApproval"> & Omit<ActionConfig<FlexibleSchema<Input>, Output>, "description" | "execute" | "inputSchema"> & {
|
|
419
|
+
description: string;
|
|
420
|
+
inputSchema: FlexibleSchema<Input>;
|
|
419
421
|
authorize?: (ctx?: Context) => boolean;
|
|
420
422
|
onUnauthorized?: UnauthorizedToolPolicy<Context>;
|
|
421
|
-
execute(input:
|
|
423
|
+
execute(input: Input, ctx: ActionContext<Context>): Promise<Output> | Output;
|
|
422
424
|
};
|
|
423
|
-
type
|
|
425
|
+
type RegisteredAction<Context extends Record<string, unknown> = Record<string, unknown>, InputSchema extends FlexibleSchema = FlexibleSchema, Output = unknown> = Action$1<InputSchema, Output> & {
|
|
424
426
|
authorize?: (ctx?: Context) => boolean;
|
|
425
427
|
onUnauthorized?: UnauthorizedToolPolicy<Context>;
|
|
426
428
|
};
|
|
427
429
|
/** A native Think action with the SDK's standard authorization policy. */
|
|
428
|
-
declare function action<Context extends Record<string, unknown> = Record<string, unknown>,
|
|
430
|
+
declare function action<Context extends Record<string, unknown> = Record<string, unknown>, Input = any, Output = any>(definition: Action<Context, Input, Output>): RegisteredAction<Context, FlexibleSchema<Input>, Output>;
|
|
429
431
|
//#endregion
|
|
430
432
|
//#region src/server/util/skills.d.ts
|
|
431
433
|
interface Skill<Context extends Record<string, unknown> = Record<string, unknown>> {
|
|
@@ -433,12 +435,12 @@ interface Skill<Context extends Record<string, unknown> = Record<string, unknown
|
|
|
433
435
|
description: string;
|
|
434
436
|
instructions: string;
|
|
435
437
|
tools?: Record<string, Tool<Context>>;
|
|
436
|
-
actions?: Record<string,
|
|
438
|
+
actions?: Record<string, RegisteredAction<Context, any, any>>;
|
|
437
439
|
authorize?: (ctx?: Context) => boolean;
|
|
438
440
|
}
|
|
439
441
|
interface SkillSource<Context extends Record<string, unknown> = Record<string, unknown>> extends SkillSource$1 {
|
|
440
442
|
tools?: Record<string, Tool<Context>>;
|
|
441
|
-
actions?: Record<string,
|
|
443
|
+
actions?: Record<string, RegisteredAction<Context, any, any>>;
|
|
442
444
|
authorize?: (ctx?: Context | undefined) => boolean;
|
|
443
445
|
}
|
|
444
446
|
declare function skill<Context extends Record<string, unknown> = Record<string, unknown>>(definition: Skill<Context>): SkillSource<Context>;
|
|
@@ -449,4 +451,4 @@ declare function routeAgentRequest<Env>(request: Request, env: Env, options?: Ag
|
|
|
449
451
|
//#region src/server/index.d.ts
|
|
450
452
|
declare function getCurrentToolContext(): any;
|
|
451
453
|
//#endregion
|
|
452
|
-
export { type Action, type
|
|
454
|
+
export { type Action, type ActionContext, Agent, type AgentConnectionStatus, type AgentConnectionType, type AgentEnv, Assistant, ChatAgent, type ExchangedToken, type JwtAuthConfig, type RegisteredAction, type Skill, type SkillSource, type TokenExchangeConfig, type TokenExchangeResult, type Tool, type ToolContext, type ToolSet, type TurnSnapshot, type UnauthorizedToolPolicy, action, createJwtAuthConfig, exchangeToken, getCurrentToolContext, routeAgentRequest, skill, tool };
|
package/dist/index.mjs
CHANGED
|
@@ -2497,10 +2497,11 @@ function action(definition) {
|
|
|
2497
2497
|
...config,
|
|
2498
2498
|
approval: config.approval ?? true,
|
|
2499
2499
|
execute: async (input, ctx) => {
|
|
2500
|
-
const
|
|
2500
|
+
const configuredKey = config.idempotencyKey;
|
|
2501
|
+
const idempotencyKey = typeof configuredKey === "function" ? await configuredKey({
|
|
2501
2502
|
input,
|
|
2502
2503
|
ctx
|
|
2503
|
-
}) :
|
|
2504
|
+
}) : typeof configuredKey === "string" ? configuredKey : ctx.toolCallId;
|
|
2504
2505
|
return execute(input, {
|
|
2505
2506
|
...ctx,
|
|
2506
2507
|
messages: [...ctx.messages],
|