lua-cli 3.12.2 → 3.13.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/dist/api/logs.api.service.d.ts +6 -3
- package/dist/api/logs.api.service.d.ts.map +1 -1
- package/dist/api/logs.api.service.js +5 -4
- package/dist/api/logs.api.service.js.map +1 -1
- package/dist/cli/command-definitions.d.ts.map +1 -1
- package/dist/cli/command-definitions.js +24 -2
- package/dist/cli/command-definitions.js.map +1 -1
- package/dist/commands/channels.d.ts.map +1 -1
- package/dist/commands/channels.js +2 -11
- package/dist/commands/channels.js.map +1 -1
- package/dist/commands/chat-log-probe.d.ts +59 -0
- package/dist/commands/chat-log-probe.d.ts.map +1 -0
- package/dist/commands/chat-log-probe.js +91 -0
- package/dist/commands/chat-log-probe.js.map +1 -0
- package/dist/commands/chat.d.ts.map +1 -1
- package/dist/commands/chat.js +111 -8
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/compile.d.ts +7 -0
- package/dist/commands/compile.d.ts.map +1 -1
- package/dist/commands/compile.js +32 -2
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/completion.d.ts.map +1 -1
- package/dist/commands/completion.js +7 -8
- package/dist/commands/completion.js.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +108 -23
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/devices.d.ts.map +1 -1
- package/dist/commands/devices.js +3 -2
- package/dist/commands/devices.js.map +1 -1
- package/dist/commands/env.d.ts.map +1 -1
- package/dist/commands/env.js +43 -20
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/features.d.ts.map +1 -1
- package/dist/commands/features.js +2 -12
- package/dist/commands/features.js.map +1 -1
- package/dist/commands/governance.d.ts.map +1 -1
- package/dist/commands/governance.js +4 -8
- package/dist/commands/governance.js.map +1 -1
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +1 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +12 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/integrations.d.ts.map +1 -1
- package/dist/commands/integrations.js +4 -2
- package/dist/commands/integrations.js.map +1 -1
- package/dist/commands/jobs.d.ts.map +1 -1
- package/dist/commands/jobs.js +61 -23
- package/dist/commands/jobs.js.map +1 -1
- package/dist/commands/log-tip.d.ts +79 -0
- package/dist/commands/log-tip.d.ts.map +1 -0
- package/dist/commands/log-tip.js +91 -0
- package/dist/commands/log-tip.js.map +1 -0
- package/dist/commands/logs.d.ts.map +1 -1
- package/dist/commands/logs.js +97 -136
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/marketplace.d.ts.map +1 -1
- package/dist/commands/marketplace.js +14 -25
- package/dist/commands/marketplace.js.map +1 -1
- package/dist/commands/mcp.d.ts.map +1 -1
- package/dist/commands/mcp.js +17 -19
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/models.d.ts.map +1 -1
- package/dist/commands/models.js +2 -1
- package/dist/commands/models.js.map +1 -1
- package/dist/commands/persona.d.ts.map +1 -1
- package/dist/commands/persona.js +4 -30
- package/dist/commands/persona.js.map +1 -1
- package/dist/commands/postprocessors.d.ts.map +1 -1
- package/dist/commands/postprocessors.js +43 -17
- package/dist/commands/postprocessors.js.map +1 -1
- package/dist/commands/preprocessors.d.ts.map +1 -1
- package/dist/commands/preprocessors.js +43 -17
- package/dist/commands/preprocessors.js.map +1 -1
- package/dist/commands/production.d.ts.map +1 -1
- package/dist/commands/production.js +2 -12
- package/dist/commands/production.js.map +1 -1
- package/dist/commands/push-helpers.d.ts +42 -0
- package/dist/commands/push-helpers.d.ts.map +1 -0
- package/dist/commands/push-helpers.js +48 -0
- package/dist/commands/push-helpers.js.map +1 -0
- package/dist/commands/push.d.ts +2 -0
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +269 -54
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/pushBackup.d.ts.map +1 -1
- package/dist/commands/pushBackup.js +7 -1
- package/dist/commands/pushBackup.js.map +1 -1
- package/dist/commands/resources.d.ts.map +1 -1
- package/dist/commands/resources.js +2 -12
- package/dist/commands/resources.js.map +1 -1
- package/dist/commands/skills.d.ts.map +1 -1
- package/dist/commands/skills.js +51 -36
- package/dist/commands/skills.js.map +1 -1
- package/dist/commands/status.d.ts +14 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +734 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +37 -2
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/telemetry.d.ts.map +1 -1
- package/dist/commands/telemetry.js +4 -0
- package/dist/commands/telemetry.js.map +1 -1
- package/dist/commands/test-output.helpers.d.ts +24 -0
- package/dist/commands/test-output.helpers.d.ts.map +1 -0
- package/dist/commands/test-output.helpers.js +62 -0
- package/dist/commands/test-output.helpers.js.map +1 -0
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +236 -76
- package/dist/commands/test.js.map +1 -1
- package/dist/commands/webhooks.d.ts.map +1 -1
- package/dist/commands/webhooks.js +34 -21
- package/dist/commands/webhooks.js.map +1 -1
- package/dist/compiler/agent-traverser.d.ts +50 -14
- package/dist/compiler/agent-traverser.d.ts.map +1 -1
- package/dist/compiler/agent-traverser.js +191 -86
- package/dist/compiler/agent-traverser.js.map +1 -1
- package/dist/compiler/compiler.d.ts +32 -0
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/compiler.js +143 -18
- package/dist/compiler/compiler.js.map +1 -1
- package/dist/compiler/index.d.ts +1 -1
- package/dist/compiler/index.d.ts.map +1 -1
- package/dist/compiler/index.js +1 -1
- package/dist/compiler/index.js.map +1 -1
- package/dist/compiler/plugins/base.d.ts +21 -0
- package/dist/compiler/plugins/base.d.ts.map +1 -1
- package/dist/compiler/plugins/base.js +10 -0
- package/dist/compiler/plugins/base.js.map +1 -1
- package/dist/compiler/plugins/skill.plugin.d.ts +35 -9
- package/dist/compiler/plugins/skill.plugin.d.ts.map +1 -1
- package/dist/compiler/plugins/skill.plugin.js +131 -84
- package/dist/compiler/plugins/skill.plugin.js.map +1 -1
- package/dist/compiler/types.d.ts +33 -0
- package/dist/compiler/types.d.ts.map +1 -1
- package/dist/compiler/types.js.map +1 -1
- package/dist/compiler/utils/ast-helpers.d.ts +1 -16
- package/dist/compiler/utils/ast-helpers.d.ts.map +1 -1
- package/dist/compiler/utils/ast-helpers.js +2 -31
- package/dist/compiler/utils/ast-helpers.js.map +1 -1
- package/dist/compiler/utils/common.d.ts +14 -0
- package/dist/compiler/utils/common.d.ts.map +1 -1
- package/dist/compiler/utils/common.js +38 -0
- package/dist/compiler/utils/common.js.map +1 -1
- package/dist/compiler/utils/path-resolver.d.ts +67 -10
- package/dist/compiler/utils/path-resolver.d.ts.map +1 -1
- package/dist/compiler/utils/path-resolver.js +120 -24
- package/dist/compiler/utils/path-resolver.js.map +1 -1
- package/dist/compiler/utils/reference-resolver.d.ts +196 -0
- package/dist/compiler/utils/reference-resolver.d.ts.map +1 -0
- package/dist/compiler/utils/reference-resolver.js +1030 -0
- package/dist/compiler/utils/reference-resolver.js.map +1 -0
- package/dist/compiler/utils/schema-converter.d.ts +25 -0
- package/dist/compiler/utils/schema-converter.d.ts.map +1 -1
- package/dist/compiler/utils/schema-converter.js +83 -4
- package/dist/compiler/utils/schema-converter.js.map +1 -1
- package/dist/compiler/utils/workspace.d.ts +35 -0
- package/dist/compiler/utils/workspace.d.ts.map +1 -0
- package/dist/compiler/utils/workspace.js +121 -0
- package/dist/compiler/utils/workspace.js.map +1 -0
- package/dist/compiler/utils/zod-runtime.mjs +5334 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/backup.d.ts +19 -1
- package/dist/interfaces/backup.d.ts.map +1 -1
- package/dist/interfaces/logs.d.ts +7 -4
- package/dist/interfaces/logs.d.ts.map +1 -1
- package/dist/primitives/base.handler.d.ts +10 -0
- package/dist/primitives/base.handler.d.ts.map +1 -1
- package/dist/primitives/base.handler.js +73 -44
- package/dist/primitives/base.handler.js.map +1 -1
- package/dist/primitives/job.handler.d.ts +5 -0
- package/dist/primitives/job.handler.d.ts.map +1 -1
- package/dist/primitives/job.handler.js +9 -0
- package/dist/primitives/job.handler.js.map +1 -1
- package/dist/primitives/webhook.handler.d.ts +2 -1
- package/dist/primitives/webhook.handler.d.ts.map +1 -1
- package/dist/primitives/webhook.handler.js +7 -1
- package/dist/primitives/webhook.handler.js.map +1 -1
- package/dist/services/auth.d.ts +8 -0
- package/dist/services/auth.d.ts.map +1 -1
- package/dist/services/auth.js +19 -0
- package/dist/services/auth.js.map +1 -1
- package/dist/services/sandbox.service.d.ts.map +1 -1
- package/dist/services/sandbox.service.js +6 -2
- package/dist/services/sandbox.service.js.map +1 -1
- package/dist/utils/aliases.d.ts +7 -0
- package/dist/utils/aliases.d.ts.map +1 -0
- package/dist/utils/aliases.js +457 -0
- package/dist/utils/aliases.js.map +1 -0
- package/dist/utils/backup-helpers.d.ts +24 -0
- package/dist/utils/backup-helpers.d.ts.map +1 -1
- package/dist/utils/backup-helpers.js +94 -8
- package/dist/utils/backup-helpers.js.map +1 -1
- package/dist/utils/cli.d.ts +24 -6
- package/dist/utils/cli.d.ts.map +1 -1
- package/dist/utils/cli.js +23 -9
- package/dist/utils/cli.js.map +1 -1
- package/dist/utils/hints.d.ts +81 -0
- package/dist/utils/hints.d.ts.map +1 -0
- package/dist/utils/hints.js +83 -0
- package/dist/utils/hints.js.map +1 -0
- package/dist/utils/suggest.d.ts +3 -0
- package/dist/utils/suggest.d.ts.map +1 -0
- package/dist/utils/suggest.js +34 -0
- package/dist/utils/suggest.js.map +1 -0
- package/dist/utils/write-info.d.ts +9 -0
- package/dist/utils/write-info.d.ts.map +1 -0
- package/dist/utils/write-info.js +11 -0
- package/dist/utils/write-info.js.map +1 -0
- package/docs/README.md +1 -1
- package/node_modules/@lua/shared-types/dist/index.d.mts +64 -2
- package/node_modules/@lua/shared-types/dist/index.d.ts +64 -2
- package/node_modules/@lua/shared-types/dist/index.js +27 -0
- package/node_modules/@lua/shared-types/dist/index.mjs +24 -0
- package/node_modules/@lua/shared-types/src/channel.type.ts +1 -0
- package/node_modules/@lua/shared-types/src/client-tools.types.ts +47 -0
- package/node_modules/@lua/shared-types/src/index.ts +2 -0
- package/node_modules/@lua/shared-types/src/vm-execution-log.types.ts +41 -0
- package/package.json +10 -6
- package/scripts/build-vendor.mjs +53 -0
- package/scripts/vendor-entry.mjs +11 -0
- package/template/examples/skills/tools/CustomDataTool.ts +1 -5
- package/template/examples/skills/tools/PremiumFeatureTool.ts +18 -18
- package/template/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure stdout writer (extracted so {@link ./hints.ts} stays importable in
|
|
3
|
+
* tests — `cli.ts` itself uses `import.meta.url` which ts-jest can't compile).
|
|
4
|
+
*
|
|
5
|
+
* Mirrors the existing `writeInfo` from `./cli.ts`: clears the current
|
|
6
|
+
* progress line via `\r\x1b[K` and writes `<message>\n`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function writeInfo(message: string): void;
|
|
9
|
+
//# sourceMappingURL=write-info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-info.d.ts","sourceRoot":"","sources":["../../src/utils/write-info.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE/C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure stdout writer (extracted so {@link ./hints.ts} stays importable in
|
|
3
|
+
* tests — `cli.ts` itself uses `import.meta.url` which ts-jest can't compile).
|
|
4
|
+
*
|
|
5
|
+
* Mirrors the existing `writeInfo` from `./cli.ts`: clears the current
|
|
6
|
+
* progress line via `\r\x1b[K` and writes `<message>\n`.
|
|
7
|
+
*/
|
|
8
|
+
export function writeInfo(message) {
|
|
9
|
+
process.stdout.write('\r\x1b[K' + message + '\n');
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=write-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-info.js","sourceRoot":"","sources":["../../src/utils/write-info.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC;AACpD,CAAC"}
|
package/docs/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Lua CLI - Complete API Documentation
|
|
2
2
|
|
|
3
|
-
Welcome to the comprehensive API documentation for lua-cli v3.
|
|
3
|
+
Welcome to the comprehensive API documentation for lua-cli v3.13.0. This guide covers every API, class, and function exported by the package.
|
|
4
4
|
|
|
5
5
|
## 📚 Documentation Index
|
|
6
6
|
|
|
@@ -5,7 +5,7 @@ import { FinishReason, LanguageModelUsage, ReasoningOutput, CallWarning, UserCon
|
|
|
5
5
|
* Represents the communication channel through which a request originated.
|
|
6
6
|
* Known channels are typed as string literals, unrecognized channels are unknown.
|
|
7
7
|
*/
|
|
8
|
-
type Channel = 'web' | 'whatsapp' | 'facebook' | 'instagram' | 'slack' | 'teams' | 'messagebird' | 'front' | 'api' | 'dev' | 'email' | 'rcs' | 'sms' | 'mms' | 'device' | string;
|
|
8
|
+
type Channel = 'web' | 'meeting' | 'whatsapp' | 'facebook' | 'instagram' | 'slack' | 'teams' | 'messagebird' | 'front' | 'api' | 'dev' | 'email' | 'rcs' | 'sms' | 'mms' | 'device' | string;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* MIME types supported by Unstructured.io for document text extraction.
|
|
@@ -337,6 +337,50 @@ interface CachedDeviceTriggerDefinition {
|
|
|
337
337
|
env: Record<string, string>;
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
+
/**
|
|
341
|
+
* Client-Injected Tools
|
|
342
|
+
*
|
|
343
|
+
* Lets a chat client (Lua Desktop, custom front-ends, future surfaces) declare
|
|
344
|
+
* tools that the agent can call but the *client* renders/handles. Mirrors the
|
|
345
|
+
* pattern used by Claude Code, OpenAI Apps SDK, and Anthropic's MCP — the
|
|
346
|
+
* surface the user sees gets to add capabilities to the agent without changing
|
|
347
|
+
* the agent itself.
|
|
348
|
+
*
|
|
349
|
+
* Tool calls flow through Mastra's existing `tool-call` stream chunks; the
|
|
350
|
+
* server registers the tool with a no-op `execute` (returns `{ ok: true,
|
|
351
|
+
* clientHandled: true }`) so the model sees a clean ack and can continue. The
|
|
352
|
+
* actual rendering / side-effect happens on the client when it sees the
|
|
353
|
+
* tool-call chunk.
|
|
354
|
+
*
|
|
355
|
+
* Tool names are namespaced server-side as `client__<name>` to avoid collisions
|
|
356
|
+
* with built-in tools (skills, MCP, devices, voice). Same pattern as device
|
|
357
|
+
* tools (`device__<name>__<command>`).
|
|
358
|
+
*/
|
|
359
|
+
interface ClientToolDef {
|
|
360
|
+
/** Unprefixed tool name as the client refers to it (e.g. "create_artifact"). Server prefixes with `client__`. */
|
|
361
|
+
name: string;
|
|
362
|
+
/** Human/LLM-readable description of when to call this tool. */
|
|
363
|
+
description: string;
|
|
364
|
+
/**
|
|
365
|
+
* JSON Schema for the tool's input. Hydrated server-side into a Zod schema
|
|
366
|
+
* via the shared `jsonSchemaToZod` util. Same subset supported as device
|
|
367
|
+
* tools — object with string/number/boolean/array properties, `required`,
|
|
368
|
+
* `default`, `description`, `enum`.
|
|
369
|
+
*/
|
|
370
|
+
parameters: Record<string, unknown>;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Server-side prefix for client tool names. Keeps client tools from
|
|
374
|
+
* shadowing skills, MCP tools, devices (`device__`), or voice tools.
|
|
375
|
+
*/
|
|
376
|
+
declare const CLIENT_TOOL_PREFIX = "client__";
|
|
377
|
+
/**
|
|
378
|
+
* Maximum number of client tools accepted per request. Keeps the model's
|
|
379
|
+
* tool list bounded — at this many tools the model starts losing precision
|
|
380
|
+
* picking the right one anyway.
|
|
381
|
+
*/
|
|
382
|
+
declare const CLIENT_TOOLS_MAX = 20;
|
|
383
|
+
|
|
340
384
|
/**
|
|
341
385
|
* Shared type definitions for the model registry.
|
|
342
386
|
*
|
|
@@ -396,4 +440,22 @@ interface GovernanceConfig {
|
|
|
396
440
|
*/
|
|
397
441
|
declare function buildDefaultPersona(agentName: string): string;
|
|
398
442
|
|
|
399
|
-
|
|
443
|
+
declare const AGENT_LOG_SOURCES: readonly ["skill", "job", "webhook", "preprocessor", "postprocessor", "user_message", "agent_response", "agent_error", "runtime", "mcp", "rag", "device", "device-trigger"];
|
|
444
|
+
type AgentLogSource = (typeof AGENT_LOG_SOURCES)[number];
|
|
445
|
+
interface AgentLogMetadata {
|
|
446
|
+
userId?: string;
|
|
447
|
+
agentId?: string;
|
|
448
|
+
/** Agent runtime / conversation thread ID for distributed tracing */
|
|
449
|
+
runId?: string;
|
|
450
|
+
logSource?: AgentLogSource;
|
|
451
|
+
/** The ID of the source entity (skillId, jobId, webhookId, etc.) */
|
|
452
|
+
primitiveId?: string;
|
|
453
|
+
/** The display name of the source entity */
|
|
454
|
+
primitiveName?: string;
|
|
455
|
+
toolId?: string;
|
|
456
|
+
toolName?: string;
|
|
457
|
+
/** Messaging channel: 'whatsapp', 'slack', 'email', etc. */
|
|
458
|
+
channel?: string;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export { AGENT_LOG_SOURCES, type AgentInvocationInput, type AgentInvocationOutput, type AgentLogMetadata, type AgentLogSource, type AiGenerateInput, type AiGenerateOutput, type AiGenerateSource, type AiGenerateToolCall, type AiGenerateToolResult, type ApprovedModelDef, type BatchingConfig, CLIENT_TOOLS_MAX, CLIENT_TOOL_PREFIX, type CachedDeviceCommand, type CachedDeviceDefinition, type CachedDeviceTrigger, type CachedDeviceTriggerDefinition, type Channel, type ClientToolDef, type CommandHashData, type CommandState, type CommandStreamEntry, type DeviceCommandDefinition, type DeviceCommandMessage, type DeviceInfo, type DeviceResponseMessage, type DeviceStatus, type DeviceTriggerAckMessage, type DeviceTriggerMessage, type GovernanceConfig, REQUIRED_ENUMS, REQUIRED_NESTED_APIS, REQUIRED_PLATFORM_APIS, REQUIRED_PRIMITIVE_SHIMS, REQUIRED_UTILITIES, type ResponseStreamEntry, type TriggerStreamEntry, UNSTRUCTURED_SUPPORTED_MEDIA_TYPES, aiGenerateInputFromSimplified, buildDefaultPersona };
|
|
@@ -5,7 +5,7 @@ import { FinishReason, LanguageModelUsage, ReasoningOutput, CallWarning, UserCon
|
|
|
5
5
|
* Represents the communication channel through which a request originated.
|
|
6
6
|
* Known channels are typed as string literals, unrecognized channels are unknown.
|
|
7
7
|
*/
|
|
8
|
-
type Channel = 'web' | 'whatsapp' | 'facebook' | 'instagram' | 'slack' | 'teams' | 'messagebird' | 'front' | 'api' | 'dev' | 'email' | 'rcs' | 'sms' | 'mms' | 'device' | string;
|
|
8
|
+
type Channel = 'web' | 'meeting' | 'whatsapp' | 'facebook' | 'instagram' | 'slack' | 'teams' | 'messagebird' | 'front' | 'api' | 'dev' | 'email' | 'rcs' | 'sms' | 'mms' | 'device' | string;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* MIME types supported by Unstructured.io for document text extraction.
|
|
@@ -337,6 +337,50 @@ interface CachedDeviceTriggerDefinition {
|
|
|
337
337
|
env: Record<string, string>;
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
+
/**
|
|
341
|
+
* Client-Injected Tools
|
|
342
|
+
*
|
|
343
|
+
* Lets a chat client (Lua Desktop, custom front-ends, future surfaces) declare
|
|
344
|
+
* tools that the agent can call but the *client* renders/handles. Mirrors the
|
|
345
|
+
* pattern used by Claude Code, OpenAI Apps SDK, and Anthropic's MCP — the
|
|
346
|
+
* surface the user sees gets to add capabilities to the agent without changing
|
|
347
|
+
* the agent itself.
|
|
348
|
+
*
|
|
349
|
+
* Tool calls flow through Mastra's existing `tool-call` stream chunks; the
|
|
350
|
+
* server registers the tool with a no-op `execute` (returns `{ ok: true,
|
|
351
|
+
* clientHandled: true }`) so the model sees a clean ack and can continue. The
|
|
352
|
+
* actual rendering / side-effect happens on the client when it sees the
|
|
353
|
+
* tool-call chunk.
|
|
354
|
+
*
|
|
355
|
+
* Tool names are namespaced server-side as `client__<name>` to avoid collisions
|
|
356
|
+
* with built-in tools (skills, MCP, devices, voice). Same pattern as device
|
|
357
|
+
* tools (`device__<name>__<command>`).
|
|
358
|
+
*/
|
|
359
|
+
interface ClientToolDef {
|
|
360
|
+
/** Unprefixed tool name as the client refers to it (e.g. "create_artifact"). Server prefixes with `client__`. */
|
|
361
|
+
name: string;
|
|
362
|
+
/** Human/LLM-readable description of when to call this tool. */
|
|
363
|
+
description: string;
|
|
364
|
+
/**
|
|
365
|
+
* JSON Schema for the tool's input. Hydrated server-side into a Zod schema
|
|
366
|
+
* via the shared `jsonSchemaToZod` util. Same subset supported as device
|
|
367
|
+
* tools — object with string/number/boolean/array properties, `required`,
|
|
368
|
+
* `default`, `description`, `enum`.
|
|
369
|
+
*/
|
|
370
|
+
parameters: Record<string, unknown>;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Server-side prefix for client tool names. Keeps client tools from
|
|
374
|
+
* shadowing skills, MCP tools, devices (`device__`), or voice tools.
|
|
375
|
+
*/
|
|
376
|
+
declare const CLIENT_TOOL_PREFIX = "client__";
|
|
377
|
+
/**
|
|
378
|
+
* Maximum number of client tools accepted per request. Keeps the model's
|
|
379
|
+
* tool list bounded — at this many tools the model starts losing precision
|
|
380
|
+
* picking the right one anyway.
|
|
381
|
+
*/
|
|
382
|
+
declare const CLIENT_TOOLS_MAX = 20;
|
|
383
|
+
|
|
340
384
|
/**
|
|
341
385
|
* Shared type definitions for the model registry.
|
|
342
386
|
*
|
|
@@ -396,4 +440,22 @@ interface GovernanceConfig {
|
|
|
396
440
|
*/
|
|
397
441
|
declare function buildDefaultPersona(agentName: string): string;
|
|
398
442
|
|
|
399
|
-
|
|
443
|
+
declare const AGENT_LOG_SOURCES: readonly ["skill", "job", "webhook", "preprocessor", "postprocessor", "user_message", "agent_response", "agent_error", "runtime", "mcp", "rag", "device", "device-trigger"];
|
|
444
|
+
type AgentLogSource = (typeof AGENT_LOG_SOURCES)[number];
|
|
445
|
+
interface AgentLogMetadata {
|
|
446
|
+
userId?: string;
|
|
447
|
+
agentId?: string;
|
|
448
|
+
/** Agent runtime / conversation thread ID for distributed tracing */
|
|
449
|
+
runId?: string;
|
|
450
|
+
logSource?: AgentLogSource;
|
|
451
|
+
/** The ID of the source entity (skillId, jobId, webhookId, etc.) */
|
|
452
|
+
primitiveId?: string;
|
|
453
|
+
/** The display name of the source entity */
|
|
454
|
+
primitiveName?: string;
|
|
455
|
+
toolId?: string;
|
|
456
|
+
toolName?: string;
|
|
457
|
+
/** Messaging channel: 'whatsapp', 'slack', 'email', etc. */
|
|
458
|
+
channel?: string;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export { AGENT_LOG_SOURCES, type AgentInvocationInput, type AgentInvocationOutput, type AgentLogMetadata, type AgentLogSource, type AiGenerateInput, type AiGenerateOutput, type AiGenerateSource, type AiGenerateToolCall, type AiGenerateToolResult, type ApprovedModelDef, type BatchingConfig, CLIENT_TOOLS_MAX, CLIENT_TOOL_PREFIX, type CachedDeviceCommand, type CachedDeviceDefinition, type CachedDeviceTrigger, type CachedDeviceTriggerDefinition, type Channel, type ClientToolDef, type CommandHashData, type CommandState, type CommandStreamEntry, type DeviceCommandDefinition, type DeviceCommandMessage, type DeviceInfo, type DeviceResponseMessage, type DeviceStatus, type DeviceTriggerAckMessage, type DeviceTriggerMessage, type GovernanceConfig, REQUIRED_ENUMS, REQUIRED_NESTED_APIS, REQUIRED_PLATFORM_APIS, REQUIRED_PRIMITIVE_SHIMS, REQUIRED_UTILITIES, type ResponseStreamEntry, type TriggerStreamEntry, UNSTRUCTURED_SUPPORTED_MEDIA_TYPES, aiGenerateInputFromSimplified, buildDefaultPersona };
|
|
@@ -20,6 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
AGENT_LOG_SOURCES: () => AGENT_LOG_SOURCES,
|
|
24
|
+
CLIENT_TOOLS_MAX: () => CLIENT_TOOLS_MAX,
|
|
25
|
+
CLIENT_TOOL_PREFIX: () => CLIENT_TOOL_PREFIX,
|
|
23
26
|
REQUIRED_ENUMS: () => REQUIRED_ENUMS,
|
|
24
27
|
REQUIRED_NESTED_APIS: () => REQUIRED_NESTED_APIS,
|
|
25
28
|
REQUIRED_PLATFORM_APIS: () => REQUIRED_PLATFORM_APIS,
|
|
@@ -208,6 +211,10 @@ var REQUIRED_UTILITIES = [
|
|
|
208
211
|
"env"
|
|
209
212
|
];
|
|
210
213
|
|
|
214
|
+
// src/client-tools.types.ts
|
|
215
|
+
var CLIENT_TOOL_PREFIX = "client__";
|
|
216
|
+
var CLIENT_TOOLS_MAX = 20;
|
|
217
|
+
|
|
211
218
|
// src/persona-defaults.ts
|
|
212
219
|
var AGENT_NAME_TOKEN = "[Your Agent Name]";
|
|
213
220
|
var DEFAULT_PERSONA_GUIDE = `# ${AGENT_NAME_TOKEN} - Persona
|
|
@@ -260,8 +267,28 @@ function buildDefaultPersona(agentName) {
|
|
|
260
267
|
return DEFAULT_PERSONA_GUIDE.replace(AGENT_NAME_TOKEN, () => agentName || "My Agent");
|
|
261
268
|
}
|
|
262
269
|
__name(buildDefaultPersona, "buildDefaultPersona");
|
|
270
|
+
|
|
271
|
+
// src/vm-execution-log.types.ts
|
|
272
|
+
var AGENT_LOG_SOURCES = [
|
|
273
|
+
"skill",
|
|
274
|
+
"job",
|
|
275
|
+
"webhook",
|
|
276
|
+
"preprocessor",
|
|
277
|
+
"postprocessor",
|
|
278
|
+
"user_message",
|
|
279
|
+
"agent_response",
|
|
280
|
+
"agent_error",
|
|
281
|
+
"runtime",
|
|
282
|
+
"mcp",
|
|
283
|
+
"rag",
|
|
284
|
+
"device",
|
|
285
|
+
"device-trigger"
|
|
286
|
+
];
|
|
263
287
|
// Annotate the CommonJS export names for ESM import in node:
|
|
264
288
|
0 && (module.exports = {
|
|
289
|
+
AGENT_LOG_SOURCES,
|
|
290
|
+
CLIENT_TOOLS_MAX,
|
|
291
|
+
CLIENT_TOOL_PREFIX,
|
|
265
292
|
REQUIRED_ENUMS,
|
|
266
293
|
REQUIRED_NESTED_APIS,
|
|
267
294
|
REQUIRED_PLATFORM_APIS,
|
|
@@ -178,6 +178,10 @@ var REQUIRED_UTILITIES = [
|
|
|
178
178
|
"env"
|
|
179
179
|
];
|
|
180
180
|
|
|
181
|
+
// src/client-tools.types.ts
|
|
182
|
+
var CLIENT_TOOL_PREFIX = "client__";
|
|
183
|
+
var CLIENT_TOOLS_MAX = 20;
|
|
184
|
+
|
|
181
185
|
// src/persona-defaults.ts
|
|
182
186
|
var AGENT_NAME_TOKEN = "[Your Agent Name]";
|
|
183
187
|
var DEFAULT_PERSONA_GUIDE = `# ${AGENT_NAME_TOKEN} - Persona
|
|
@@ -230,7 +234,27 @@ function buildDefaultPersona(agentName) {
|
|
|
230
234
|
return DEFAULT_PERSONA_GUIDE.replace(AGENT_NAME_TOKEN, () => agentName || "My Agent");
|
|
231
235
|
}
|
|
232
236
|
__name(buildDefaultPersona, "buildDefaultPersona");
|
|
237
|
+
|
|
238
|
+
// src/vm-execution-log.types.ts
|
|
239
|
+
var AGENT_LOG_SOURCES = [
|
|
240
|
+
"skill",
|
|
241
|
+
"job",
|
|
242
|
+
"webhook",
|
|
243
|
+
"preprocessor",
|
|
244
|
+
"postprocessor",
|
|
245
|
+
"user_message",
|
|
246
|
+
"agent_response",
|
|
247
|
+
"agent_error",
|
|
248
|
+
"runtime",
|
|
249
|
+
"mcp",
|
|
250
|
+
"rag",
|
|
251
|
+
"device",
|
|
252
|
+
"device-trigger"
|
|
253
|
+
];
|
|
233
254
|
export {
|
|
255
|
+
AGENT_LOG_SOURCES,
|
|
256
|
+
CLIENT_TOOLS_MAX,
|
|
257
|
+
CLIENT_TOOL_PREFIX,
|
|
234
258
|
REQUIRED_ENUMS,
|
|
235
259
|
REQUIRED_NESTED_APIS,
|
|
236
260
|
REQUIRED_PLATFORM_APIS,
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-Injected Tools
|
|
3
|
+
*
|
|
4
|
+
* Lets a chat client (Lua Desktop, custom front-ends, future surfaces) declare
|
|
5
|
+
* tools that the agent can call but the *client* renders/handles. Mirrors the
|
|
6
|
+
* pattern used by Claude Code, OpenAI Apps SDK, and Anthropic's MCP — the
|
|
7
|
+
* surface the user sees gets to add capabilities to the agent without changing
|
|
8
|
+
* the agent itself.
|
|
9
|
+
*
|
|
10
|
+
* Tool calls flow through Mastra's existing `tool-call` stream chunks; the
|
|
11
|
+
* server registers the tool with a no-op `execute` (returns `{ ok: true,
|
|
12
|
+
* clientHandled: true }`) so the model sees a clean ack and can continue. The
|
|
13
|
+
* actual rendering / side-effect happens on the client when it sees the
|
|
14
|
+
* tool-call chunk.
|
|
15
|
+
*
|
|
16
|
+
* Tool names are namespaced server-side as `client__<name>` to avoid collisions
|
|
17
|
+
* with built-in tools (skills, MCP, devices, voice). Same pattern as device
|
|
18
|
+
* tools (`device__<name>__<command>`).
|
|
19
|
+
*/
|
|
20
|
+
export interface ClientToolDef {
|
|
21
|
+
/** Unprefixed tool name as the client refers to it (e.g. "create_artifact"). Server prefixes with `client__`. */
|
|
22
|
+
name: string;
|
|
23
|
+
|
|
24
|
+
/** Human/LLM-readable description of when to call this tool. */
|
|
25
|
+
description: string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* JSON Schema for the tool's input. Hydrated server-side into a Zod schema
|
|
29
|
+
* via the shared `jsonSchemaToZod` util. Same subset supported as device
|
|
30
|
+
* tools — object with string/number/boolean/array properties, `required`,
|
|
31
|
+
* `default`, `description`, `enum`.
|
|
32
|
+
*/
|
|
33
|
+
parameters: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Server-side prefix for client tool names. Keeps client tools from
|
|
38
|
+
* shadowing skills, MCP tools, devices (`device__`), or voice tools.
|
|
39
|
+
*/
|
|
40
|
+
export const CLIENT_TOOL_PREFIX = 'client__';
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Maximum number of client tools accepted per request. Keeps the model's
|
|
44
|
+
* tool list bounded — at this many tools the model starts losing precision
|
|
45
|
+
* picking the right one anyway.
|
|
46
|
+
*/
|
|
47
|
+
export const CLIENT_TOOLS_MAX = 20;
|
|
@@ -5,6 +5,8 @@ export * from './ai-generate.utils';
|
|
|
5
5
|
export * from './agent-invocation.types';
|
|
6
6
|
export * from './sandbox-contract';
|
|
7
7
|
export * from './device.types';
|
|
8
|
+
export * from './client-tools.types';
|
|
8
9
|
export * from './model-registry';
|
|
9
10
|
export * from './agent-config.types';
|
|
10
11
|
export * from './persona-defaults';
|
|
12
|
+
export * from './vm-execution-log.types';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// ─── Canonical log-source enum ────────────────────────────────────────────────
|
|
2
|
+
// Single source of truth for all `logSource` values written to the
|
|
3
|
+
// `vmExecutionLogs` collection. Every consumer (lua-core, lua-api, lua-cli,
|
|
4
|
+
// lua-web) must import from here — never define the union inline elsewhere.
|
|
5
|
+
//
|
|
6
|
+
// NOTE: This lives in shared-types (not shared-schemas) so that lightweight
|
|
7
|
+
// consumers such as lua-cli can import it without pulling in Mongoose schemas.
|
|
8
|
+
|
|
9
|
+
export const AGENT_LOG_SOURCES = [
|
|
10
|
+
'skill', // User-defined skill executions
|
|
11
|
+
'job', // Scheduled job executions
|
|
12
|
+
'webhook', // HTTP webhook endpoint executions
|
|
13
|
+
'preprocessor', // Message preprocessor executions
|
|
14
|
+
'postprocessor', // Response postprocessor executions
|
|
15
|
+
'user_message', // Incoming user messages
|
|
16
|
+
'agent_response', // Outgoing agent responses
|
|
17
|
+
'agent_error', // Chat pipeline errors (billing, validation, LLM failures)
|
|
18
|
+
'runtime', // Agent runtime / LLM SDK / MCP transport / framework-level logs
|
|
19
|
+
'mcp', // MCP tool executions
|
|
20
|
+
'rag', // RAG knowledge-base search executions
|
|
21
|
+
'device', // Device command executions
|
|
22
|
+
'device-trigger', // Device trigger handler executions
|
|
23
|
+
] as const;
|
|
24
|
+
|
|
25
|
+
export type AgentLogSource = (typeof AGENT_LOG_SOURCES)[number];
|
|
26
|
+
|
|
27
|
+
export interface AgentLogMetadata {
|
|
28
|
+
userId?: string;
|
|
29
|
+
agentId?: string;
|
|
30
|
+
/** Agent runtime / conversation thread ID for distributed tracing */
|
|
31
|
+
runId?: string;
|
|
32
|
+
logSource?: AgentLogSource;
|
|
33
|
+
/** The ID of the source entity (skillId, jobId, webhookId, etc.) */
|
|
34
|
+
primitiveId?: string;
|
|
35
|
+
/** The display name of the source entity */
|
|
36
|
+
primitiveName?: string;
|
|
37
|
+
toolId?: string;
|
|
38
|
+
toolName?: string;
|
|
39
|
+
/** Messaging channel: 'whatsapp', 'slack', 'email', etc. */
|
|
40
|
+
channel?: string;
|
|
41
|
+
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lua-cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.0",
|
|
4
4
|
"description": "Build, test, and deploy AI agents with custom tools, webhooks, and scheduled jobs. Features LuaAgent unified configuration, streaming chat, and batch deployment.",
|
|
5
5
|
"readmeFilename": "README.md",
|
|
6
6
|
"main": "dist/api-exports.js",
|
|
7
7
|
"bin": {
|
|
8
|
-
"lua": "./dist/index.js"
|
|
8
|
+
"lua": "./dist/index.js",
|
|
9
|
+
"heylua": "./dist/index.js",
|
|
10
|
+
"lua-ai": "./dist/index.js"
|
|
9
11
|
},
|
|
10
12
|
"exports": {
|
|
11
13
|
".": "./dist/api-exports.js"
|
|
12
14
|
},
|
|
13
15
|
"scripts": {
|
|
14
16
|
"clean": "rm -rf dist",
|
|
15
|
-
"build": "npm run clean && tsc && chmod +x dist/index.js",
|
|
17
|
+
"build": "npm run clean && tsc && npm run build:vendor && chmod +x dist/index.js",
|
|
18
|
+
"build:vendor": "node scripts/build-vendor.mjs",
|
|
16
19
|
"prepack": "node scripts/resolve-workspace-deps.cjs",
|
|
17
20
|
"postpack": "git checkout package.json",
|
|
18
21
|
"prepublishOnly": "npm run build",
|
|
@@ -61,7 +64,7 @@
|
|
|
61
64
|
"LICENSE"
|
|
62
65
|
],
|
|
63
66
|
"dependencies": {
|
|
64
|
-
"@lua/shared-types": "
|
|
67
|
+
"@lua/shared-types": "0.0.1",
|
|
65
68
|
"@tailwindcss/postcss": "^4.1.14",
|
|
66
69
|
"@tanstack/react-query": "^5.90.11",
|
|
67
70
|
"@truestamp/canonify": "^2.1.0",
|
|
@@ -78,13 +81,15 @@
|
|
|
78
81
|
"posthog-node": "^5.26.0",
|
|
79
82
|
"ts-evaluator": "^2.0.0",
|
|
80
83
|
"ts-morph": "^27.0.0",
|
|
81
|
-
"zod": "^3.
|
|
84
|
+
"zod": "^3.25.76",
|
|
82
85
|
"zod-to-json-schema": "^3.24.6"
|
|
83
86
|
},
|
|
84
87
|
"bundledDependencies": [
|
|
85
88
|
"@lua/shared-types"
|
|
86
89
|
],
|
|
87
90
|
"devDependencies": {
|
|
91
|
+
"@swc/core": "^1.15.0",
|
|
92
|
+
"@swc/jest": "^0.2.39",
|
|
88
93
|
"@types/diff": "^7.0.2",
|
|
89
94
|
"@types/inquirer": "^9.0.9",
|
|
90
95
|
"@types/jest": "^29.5.8",
|
|
@@ -96,7 +101,6 @@
|
|
|
96
101
|
"lodash": "^4.17.21",
|
|
97
102
|
"nock": "^14.0.11",
|
|
98
103
|
"stripe": "^19.2.0",
|
|
99
|
-
"ts-jest": "^29.1.1",
|
|
100
104
|
"ts-node": "^10.9.2",
|
|
101
105
|
"typescript": "^5.9.2"
|
|
102
106
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Bundles `zod` and `zod-to-json-schema` into a single self-contained ESM
|
|
4
|
+
* file at `dist/compiler/utils/zod-runtime.mjs`.
|
|
5
|
+
*
|
|
6
|
+
* Why: `schema-converter.ts` previously did `await import('zod')` at runtime,
|
|
7
|
+
* which made the compiler depend on the user's `lua-cli/node_modules/zod`
|
|
8
|
+
* being intact. Real-world npm/pnpm installs are sometimes corrupted (empty
|
|
9
|
+
* package dirs, partial extracts, hoisting conflicts), causing the dynamic
|
|
10
|
+
* import to throw `ERR_MODULE_NOT_FOUND` and tools to ship with no
|
|
11
|
+
* `inputSchema` — a silent failure that breaks deployed agents.
|
|
12
|
+
*
|
|
13
|
+
* This script ships zod inside lua-cli's own dist folder so resolution is
|
|
14
|
+
* anchored to a path lua-cli fully controls (`import.meta.url`-relative).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { build } from 'esbuild';
|
|
18
|
+
import { fileURLToPath } from 'node:url';
|
|
19
|
+
import path from 'node:path';
|
|
20
|
+
import fs from 'node:fs/promises';
|
|
21
|
+
|
|
22
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
23
|
+
const __dirname = path.dirname(__filename);
|
|
24
|
+
|
|
25
|
+
const packageRoot = path.resolve(__dirname, '..');
|
|
26
|
+
const entry = path.join(packageRoot, 'scripts', 'vendor-entry.mjs');
|
|
27
|
+
const outdir = path.join(packageRoot, 'dist', 'compiler', 'utils');
|
|
28
|
+
const outfile = path.join(outdir, 'zod-runtime.mjs');
|
|
29
|
+
|
|
30
|
+
await fs.mkdir(outdir, { recursive: true });
|
|
31
|
+
|
|
32
|
+
const result = await build({
|
|
33
|
+
entryPoints: [entry],
|
|
34
|
+
outfile,
|
|
35
|
+
bundle: true,
|
|
36
|
+
format: 'esm',
|
|
37
|
+
platform: 'node',
|
|
38
|
+
target: 'node18',
|
|
39
|
+
// Keep readable bundle so stack traces remain useful when something goes
|
|
40
|
+
// wrong in user-supplied zod schemas.
|
|
41
|
+
minify: false,
|
|
42
|
+
sourcemap: false,
|
|
43
|
+
legalComments: 'none',
|
|
44
|
+
metafile: true,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const stat = await fs.stat(outfile);
|
|
48
|
+
const sizeKb = (stat.size / 1024).toFixed(1);
|
|
49
|
+
|
|
50
|
+
const inputs = Object.keys(result.metafile.inputs).filter(
|
|
51
|
+
(p) => p.includes('node_modules/zod') || p.includes('node_modules/zod-to-json-schema'),
|
|
52
|
+
);
|
|
53
|
+
console.log(`✅ Vendored ${inputs.length} files into dist/compiler/utils/zod-runtime.mjs (${sizeKb} KB)`);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendor entry point for the schema converter runtime.
|
|
3
|
+
*
|
|
4
|
+
* Bundled by `scripts/build-vendor.mjs` into
|
|
5
|
+
* `dist/compiler/utils/zod-runtime.mjs` so the compiler does not depend on
|
|
6
|
+
* `node_modules/zod` resolution at runtime. See
|
|
7
|
+
* `src/compiler/utils/schema-converter.ts` for the consumer.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export { z } from 'zod';
|
|
11
|
+
export { zodToJsonSchema } from 'zod-to-json-schema';
|
|
@@ -77,11 +77,7 @@ export class UpdateMovieTool implements LuaTool {
|
|
|
77
77
|
searchText: z.string().optional().describe("Updated search text for better discoverability")
|
|
78
78
|
});
|
|
79
79
|
async execute(input: z.infer<typeof this.inputSchema>) {
|
|
80
|
-
|
|
81
|
-
if (input.searchText) {
|
|
82
|
-
updateData.searchText = input.searchText;
|
|
83
|
-
}
|
|
84
|
-
return Data.update("movies", input.movieId, updateData);
|
|
80
|
+
return Data.update("movies", input.movieId, input.updates, input.searchText);
|
|
85
81
|
}
|
|
86
82
|
}
|
|
87
83
|
|
|
@@ -27,7 +27,7 @@ export default class PremiumFeatureTool implements LuaTool {
|
|
|
27
27
|
minPrice: z.number().optional().describe("Minimum price filter"),
|
|
28
28
|
maxPrice: z.number().optional().describe("Maximum price filter"),
|
|
29
29
|
}).optional().describe("Optional filters"),
|
|
30
|
-
sortBy: z.enum(["relevance", "price_asc", "price_desc"
|
|
30
|
+
sortBy: z.enum(["relevance", "price_asc", "price_desc"]).optional().describe("Sort order")
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
/**
|
|
@@ -39,8 +39,9 @@ export default class PremiumFeatureTool implements LuaTool {
|
|
|
39
39
|
* If condition throws an error, the tool is disabled (fail-closed behavior).
|
|
40
40
|
*/
|
|
41
41
|
condition = async () => {
|
|
42
|
-
// Get the current user's data
|
|
42
|
+
// Get the current user's data (returns null when called outside a conversation)
|
|
43
43
|
const user = await User.get();
|
|
44
|
+
if (!user) return false;
|
|
44
45
|
|
|
45
46
|
// Check if user has premium subscription
|
|
46
47
|
// The 'data' field contains custom user data stored via User.update()
|
|
@@ -58,33 +59,32 @@ export default class PremiumFeatureTool implements LuaTool {
|
|
|
58
59
|
// This only runs if condition returned true
|
|
59
60
|
const { query, filters, sortBy } = input;
|
|
60
61
|
|
|
61
|
-
//
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
limit: 20,
|
|
65
|
-
};
|
|
62
|
+
// Products.search(query) — returns ProductSearchInstance (iterable, has .products)
|
|
63
|
+
const searchResult = await Products.search(query);
|
|
64
|
+
const products = searchResult.products;
|
|
66
65
|
|
|
66
|
+
// Apply filters client-side
|
|
67
|
+
let filteredResults = products;
|
|
68
|
+
|
|
67
69
|
if (filters?.category) {
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (sortBy) {
|
|
72
|
-
searchOptions.sortBy = sortBy;
|
|
70
|
+
filteredResults = filteredResults.filter(p => p.category === filters.category);
|
|
73
71
|
}
|
|
74
72
|
|
|
75
|
-
const searchResult = await Products.search(searchOptions);
|
|
76
|
-
const products = searchResult.products;
|
|
77
|
-
|
|
78
|
-
// Apply price filters if provided
|
|
79
|
-
let filteredResults = products;
|
|
80
73
|
if (filters?.minPrice !== undefined || filters?.maxPrice !== undefined) {
|
|
81
|
-
filteredResults =
|
|
74
|
+
filteredResults = filteredResults.filter((product) => {
|
|
82
75
|
const price = product.price || 0;
|
|
83
76
|
if (filters.minPrice !== undefined && price < filters.minPrice) return false;
|
|
84
77
|
if (filters.maxPrice !== undefined && price > filters.maxPrice) return false;
|
|
85
78
|
return true;
|
|
86
79
|
});
|
|
87
80
|
}
|
|
81
|
+
|
|
82
|
+
// Sort client-side when requested
|
|
83
|
+
if (sortBy === "price_asc") {
|
|
84
|
+
filteredResults = [...filteredResults].sort((a, b) => (a.price || 0) - (b.price || 0));
|
|
85
|
+
} else if (sortBy === "price_desc") {
|
|
86
|
+
filteredResults = [...filteredResults].sort((a, b) => (b.price || 0) - (a.price || 0));
|
|
87
|
+
}
|
|
88
88
|
|
|
89
89
|
return {
|
|
90
90
|
query,
|