@warlock.js/ai 4.1.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 +72 -0
- package/cjs/index.cjs +8625 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/agent/agent-config.type.d.mts +160 -0
- package/esm/agent/agent-config.type.d.mts.map +1 -0
- package/esm/agent/agent-input-builder.mjs +111 -0
- package/esm/agent/agent-input-builder.mjs.map +1 -0
- package/esm/agent/agent-log-event.mjs +101 -0
- package/esm/agent/agent-log-event.mjs.map +1 -0
- package/esm/agent/agent-stream.d.mts +47 -0
- package/esm/agent/agent-stream.d.mts.map +1 -0
- package/esm/agent/agent-stream.mjs +82 -0
- package/esm/agent/agent-stream.mjs.map +1 -0
- package/esm/agent/agent-to-stream-event.mjs +86 -0
- package/esm/agent/agent-to-stream-event.mjs.map +1 -0
- package/esm/agent/agent.d.mts +38 -0
- package/esm/agent/agent.d.mts.map +1 -0
- package/esm/agent/agent.mjs +974 -0
- package/esm/agent/agent.mjs.map +1 -0
- package/esm/agent/index.d.mts +3 -0
- package/esm/agent/index.mjs +4 -0
- package/esm/agent/json-stream-guard.mjs +400 -0
- package/esm/agent/json-stream-guard.mjs.map +1 -0
- package/esm/ai.d.mts +64 -0
- package/esm/ai.d.mts.map +1 -0
- package/esm/ai.mjs +65 -0
- package/esm/ai.mjs.map +1 -0
- package/esm/config.d.mts +79 -0
- package/esm/config.d.mts.map +1 -0
- package/esm/config.mjs +43 -0
- package/esm/config.mjs.map +1 -0
- package/esm/contracts/agent/agent-options.type.d.mts +132 -0
- package/esm/contracts/agent/agent-options.type.d.mts.map +1 -0
- package/esm/contracts/agent/agent.contract.d.mts +92 -0
- package/esm/contracts/agent/agent.contract.d.mts.map +1 -0
- package/esm/contracts/agent/index.d.mts +2 -0
- package/esm/contracts/attachment.type.d.mts +100 -0
- package/esm/contracts/attachment.type.d.mts.map +1 -0
- package/esm/contracts/content-part.type.d.mts +55 -0
- package/esm/contracts/content-part.type.d.mts.map +1 -0
- package/esm/contracts/conversation-message.type.d.mts +51 -0
- package/esm/contracts/conversation-message.type.d.mts.map +1 -0
- package/esm/contracts/embedder.contract.d.mts +69 -0
- package/esm/contracts/embedder.contract.d.mts.map +1 -0
- package/esm/contracts/end.type.d.mts +53 -0
- package/esm/contracts/end.type.d.mts.map +1 -0
- package/esm/contracts/end.type.mjs +47 -0
- package/esm/contracts/end.type.mjs.map +1 -0
- package/esm/contracts/events/agent-events.type.d.mts +71 -0
- package/esm/contracts/events/agent-events.type.d.mts.map +1 -0
- package/esm/contracts/events/complete-event.type.d.mts +33 -0
- package/esm/contracts/events/complete-event.type.d.mts.map +1 -0
- package/esm/contracts/events/event-identity.type.d.mts +30 -0
- package/esm/contracts/events/event-identity.type.d.mts.map +1 -0
- package/esm/contracts/events/event-map.type.d.mts +80 -0
- package/esm/contracts/events/event-map.type.d.mts.map +1 -0
- package/esm/contracts/events/index.d.mts +7 -0
- package/esm/contracts/events/supervisor-events.type.d.mts +162 -0
- package/esm/contracts/events/supervisor-events.type.d.mts.map +1 -0
- package/esm/contracts/events/usage-event.type.d.mts +39 -0
- package/esm/contracts/events/usage-event.type.d.mts.map +1 -0
- package/esm/contracts/events/workflow-events.type.d.mts +51 -0
- package/esm/contracts/events/workflow-events.type.d.mts.map +1 -0
- package/esm/contracts/executable.contract.d.mts +25 -0
- package/esm/contracts/executable.contract.d.mts.map +1 -0
- package/esm/contracts/finish-reason.type.d.mts +17 -0
- package/esm/contracts/finish-reason.type.d.mts.map +1 -0
- package/esm/contracts/index.d.mts +63 -0
- package/esm/contracts/middleware/index.d.mts +3 -0
- package/esm/contracts/middleware/middleware-context.type.d.mts +99 -0
- package/esm/contracts/middleware/middleware-context.type.d.mts.map +1 -0
- package/esm/contracts/middleware/middleware-state.type.d.mts +34 -0
- package/esm/contracts/middleware/middleware-state.type.d.mts.map +1 -0
- package/esm/contracts/middleware/middleware.contract.d.mts +140 -0
- package/esm/contracts/middleware/middleware.contract.d.mts.map +1 -0
- package/esm/contracts/model-tool-call-request.type.d.mts +58 -0
- package/esm/contracts/model-tool-call-request.type.d.mts.map +1 -0
- package/esm/contracts/model.contract.d.mts +164 -0
- package/esm/contracts/model.contract.d.mts.map +1 -0
- package/esm/contracts/placeholders.type.d.mts +23 -0
- package/esm/contracts/placeholders.type.d.mts.map +1 -0
- package/esm/contracts/result/agent-result.type.d.mts +33 -0
- package/esm/contracts/result/agent-result.type.d.mts.map +1 -0
- package/esm/contracts/result/attempt-entry.type.d.mts +40 -0
- package/esm/contracts/result/attempt-entry.type.d.mts.map +1 -0
- package/esm/contracts/result/base-report.type.d.mts +137 -0
- package/esm/contracts/result/base-report.type.d.mts.map +1 -0
- package/esm/contracts/result/base-report.type.mjs +17 -0
- package/esm/contracts/result/base-report.type.mjs.map +1 -0
- package/esm/contracts/result/base-result.type.d.mts +26 -0
- package/esm/contracts/result/base-result.type.d.mts.map +1 -0
- package/esm/contracts/result/execute-result.type.d.mts +40 -0
- package/esm/contracts/result/execute-result.type.d.mts.map +1 -0
- package/esm/contracts/result/execution-report.type.d.mts +50 -0
- package/esm/contracts/result/execution-report.type.d.mts.map +1 -0
- package/esm/contracts/result/index.d.mts +14 -0
- package/esm/contracts/result/llm-trip.type.d.mts +36 -0
- package/esm/contracts/result/llm-trip.type.d.mts.map +1 -0
- package/esm/contracts/result/model-pricing.type.d.mts +51 -0
- package/esm/contracts/result/model-pricing.type.d.mts.map +1 -0
- package/esm/contracts/result/session-send-result.type.d.mts +29 -0
- package/esm/contracts/result/session-send-result.type.d.mts.map +1 -0
- package/esm/contracts/result/step-result.type.d.mts +43 -0
- package/esm/contracts/result/step-result.type.d.mts.map +1 -0
- package/esm/contracts/result/supervisor-result.type.d.mts +86 -0
- package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -0
- package/esm/contracts/result/tool-call.type.d.mts +44 -0
- package/esm/contracts/result/tool-call.type.d.mts.map +1 -0
- package/esm/contracts/result/usage.type.d.mts +57 -0
- package/esm/contracts/result/usage.type.d.mts.map +1 -0
- package/esm/contracts/result/workflow-result.type.d.mts +45 -0
- package/esm/contracts/result/workflow-result.type.d.mts.map +1 -0
- package/esm/contracts/sdk-adapter.contract.d.mts +77 -0
- package/esm/contracts/sdk-adapter.contract.d.mts.map +1 -0
- package/esm/contracts/stream/stream-event.type.d.mts +68 -0
- package/esm/contracts/stream/stream-event.type.d.mts.map +1 -0
- package/esm/contracts/stream/stream.contract.d.mts +61 -0
- package/esm/contracts/stream/stream.contract.d.mts.map +1 -0
- package/esm/contracts/streaming-tool-guard-config.type.d.mts +78 -0
- package/esm/contracts/streaming-tool-guard-config.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/ack-entry.type.d.mts +97 -0
- package/esm/contracts/supervisor/ack-entry.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/classifier-context.type.d.mts +189 -0
- package/esm/contracts/supervisor/classifier-context.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/dispatch-context.type.d.mts +235 -0
- package/esm/contracts/supervisor/dispatch-context.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/evaluate-context.type.d.mts +124 -0
- package/esm/contracts/supervisor/evaluate-context.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/index.d.mts +16 -0
- package/esm/contracts/supervisor/intent-entry.type.d.mts +254 -0
- package/esm/contracts/supervisor/intent-entry.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/iteration-snapshot.type.d.mts +117 -0
- package/esm/contracts/supervisor/iteration-snapshot.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/next.type.d.mts +25 -0
- package/esm/contracts/supervisor/next.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/route-context.type.d.mts +91 -0
- package/esm/contracts/supervisor/route-context.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/router-entry.type.d.mts +67 -0
- package/esm/contracts/supervisor/router-entry.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-config.type.d.mts +356 -0
- package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-execute-options.type.d.mts +90 -0
- package/esm/contracts/supervisor/supervisor-execute-options.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-input.type.d.mts +24 -0
- package/esm/contracts/supervisor/supervisor-input.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts +49 -0
- package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-stream-event.type.d.mts +16 -0
- package/esm/contracts/supervisor/supervisor-stream-event.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor.contract.d.mts +126 -0
- package/esm/contracts/supervisor/supervisor.contract.d.mts.map +1 -0
- package/esm/contracts/system-prompt.contract.d.mts +118 -0
- package/esm/contracts/system-prompt.contract.d.mts.map +1 -0
- package/esm/contracts/tool.contract.d.mts +161 -0
- package/esm/contracts/tool.contract.d.mts.map +1 -0
- package/esm/contracts/workflow/index.d.mts +6 -0
- package/esm/contracts/workflow/next-step-result.type.d.mts +17 -0
- package/esm/contracts/workflow/next-step-result.type.d.mts.map +1 -0
- package/esm/contracts/workflow/retry-config.type.d.mts +19 -0
- package/esm/contracts/workflow/retry-config.type.d.mts.map +1 -0
- package/esm/contracts/workflow/step.contract.d.mts +189 -0
- package/esm/contracts/workflow/step.contract.d.mts.map +1 -0
- package/esm/contracts/workflow/workflow-context.type.d.mts +45 -0
- package/esm/contracts/workflow/workflow-context.type.d.mts.map +1 -0
- package/esm/contracts/workflow/workflow-snapshot.type.d.mts +24 -0
- package/esm/contracts/workflow/workflow-snapshot.type.d.mts.map +1 -0
- package/esm/contracts/workflow/workflow.contract.d.mts +142 -0
- package/esm/contracts/workflow/workflow.contract.d.mts.map +1 -0
- package/esm/errors/agent-cancelled-error.d.mts +49 -0
- package/esm/errors/agent-cancelled-error.d.mts.map +1 -0
- package/esm/errors/agent-cancelled-error.mjs +43 -0
- package/esm/errors/agent-cancelled-error.mjs.map +1 -0
- package/esm/errors/agent-execution-error.d.mts +32 -0
- package/esm/errors/agent-execution-error.d.mts.map +1 -0
- package/esm/errors/agent-execution-error.mjs +35 -0
- package/esm/errors/agent-execution-error.mjs.map +1 -0
- package/esm/errors/agent-max-trips-error.d.mts +45 -0
- package/esm/errors/agent-max-trips-error.d.mts.map +1 -0
- package/esm/errors/agent-max-trips-error.mjs +41 -0
- package/esm/errors/agent-max-trips-error.mjs.map +1 -0
- package/esm/errors/ai-error.d.mts +94 -0
- package/esm/errors/ai-error.d.mts.map +1 -0
- package/esm/errors/ai-error.mjs +68 -0
- package/esm/errors/ai-error.mjs.map +1 -0
- package/esm/errors/budget-exceeded-error.d.mts +41 -0
- package/esm/errors/budget-exceeded-error.d.mts.map +1 -0
- package/esm/errors/budget-exceeded-error.mjs +31 -0
- package/esm/errors/budget-exceeded-error.mjs.map +1 -0
- package/esm/errors/content-filter-error.d.mts +33 -0
- package/esm/errors/content-filter-error.d.mts.map +1 -0
- package/esm/errors/content-filter-error.mjs +28 -0
- package/esm/errors/content-filter-error.mjs.map +1 -0
- package/esm/errors/context-length-exceeded-error.d.mts +38 -0
- package/esm/errors/context-length-exceeded-error.d.mts.map +1 -0
- package/esm/errors/context-length-exceeded-error.mjs +31 -0
- package/esm/errors/context-length-exceeded-error.mjs.map +1 -0
- package/esm/errors/error-category.type.d.mts +30 -0
- package/esm/errors/error-category.type.d.mts.map +1 -0
- package/esm/errors/error-code.type.d.mts +19 -0
- package/esm/errors/error-code.type.d.mts.map +1 -0
- package/esm/errors/guardrail-violation-error.d.mts +55 -0
- package/esm/errors/guardrail-violation-error.d.mts.map +1 -0
- package/esm/errors/guardrail-violation-error.mjs +41 -0
- package/esm/errors/guardrail-violation-error.mjs.map +1 -0
- package/esm/errors/index.d.mts +29 -0
- package/esm/errors/index.mjs +29 -0
- package/esm/errors/invalid-request-error.d.mts +27 -0
- package/esm/errors/invalid-request-error.d.mts.map +1 -0
- package/esm/errors/invalid-request-error.mjs +31 -0
- package/esm/errors/invalid-request-error.mjs.map +1 -0
- package/esm/errors/max-iterations-error.d.mts +31 -0
- package/esm/errors/max-iterations-error.d.mts.map +1 -0
- package/esm/errors/max-iterations-error.mjs +32 -0
- package/esm/errors/max-iterations-error.mjs.map +1 -0
- package/esm/errors/max-steps-exceeded-error.d.mts +20 -0
- package/esm/errors/max-steps-exceeded-error.d.mts.map +1 -0
- package/esm/errors/max-steps-exceeded-error.mjs +21 -0
- package/esm/errors/max-steps-exceeded-error.mjs.map +1 -0
- package/esm/errors/provider-auth-error.d.mts +22 -0
- package/esm/errors/provider-auth-error.d.mts.map +1 -0
- package/esm/errors/provider-auth-error.mjs +26 -0
- package/esm/errors/provider-auth-error.mjs.map +1 -0
- package/esm/errors/provider-error.d.mts +38 -0
- package/esm/errors/provider-error.d.mts.map +1 -0
- package/esm/errors/provider-error.mjs +42 -0
- package/esm/errors/provider-error.mjs.map +1 -0
- package/esm/errors/provider-rate-limit-error.d.mts +34 -0
- package/esm/errors/provider-rate-limit-error.d.mts.map +1 -0
- package/esm/errors/provider-rate-limit-error.mjs +31 -0
- package/esm/errors/provider-rate-limit-error.mjs.map +1 -0
- package/esm/errors/provider-timeout-error.d.mts +22 -0
- package/esm/errors/provider-timeout-error.d.mts.map +1 -0
- package/esm/errors/provider-timeout-error.mjs +26 -0
- package/esm/errors/provider-timeout-error.mjs.map +1 -0
- package/esm/errors/quota-exceeded-error.d.mts +36 -0
- package/esm/errors/quota-exceeded-error.d.mts.map +1 -0
- package/esm/errors/quota-exceeded-error.mjs +40 -0
- package/esm/errors/quota-exceeded-error.mjs.map +1 -0
- package/esm/errors/routing-error.d.mts +23 -0
- package/esm/errors/routing-error.d.mts.map +1 -0
- package/esm/errors/routing-error.mjs +23 -0
- package/esm/errors/routing-error.mjs.map +1 -0
- package/esm/errors/schema-validation-error.d.mts +40 -0
- package/esm/errors/schema-validation-error.d.mts.map +1 -0
- package/esm/errors/schema-validation-error.mjs +37 -0
- package/esm/errors/schema-validation-error.mjs.map +1 -0
- package/esm/errors/step-failed-error.d.mts +20 -0
- package/esm/errors/step-failed-error.d.mts.map +1 -0
- package/esm/errors/step-failed-error.mjs +19 -0
- package/esm/errors/step-failed-error.mjs.map +1 -0
- package/esm/errors/supervisor-cancelled-error.d.mts +29 -0
- package/esm/errors/supervisor-cancelled-error.d.mts.map +1 -0
- package/esm/errors/supervisor-cancelled-error.mjs +29 -0
- package/esm/errors/supervisor-cancelled-error.mjs.map +1 -0
- package/esm/errors/supervisor-drift-error.d.mts +31 -0
- package/esm/errors/supervisor-drift-error.d.mts.map +1 -0
- package/esm/errors/supervisor-drift-error.mjs +30 -0
- package/esm/errors/supervisor-drift-error.mjs.map +1 -0
- package/esm/errors/supervisor-failed-error.d.mts +40 -0
- package/esm/errors/supervisor-failed-error.d.mts.map +1 -0
- package/esm/errors/supervisor-failed-error.mjs +43 -0
- package/esm/errors/supervisor-failed-error.mjs.map +1 -0
- package/esm/errors/supervisor-routing-error.d.mts +44 -0
- package/esm/errors/supervisor-routing-error.d.mts.map +1 -0
- package/esm/errors/supervisor-routing-error.mjs +39 -0
- package/esm/errors/supervisor-routing-error.mjs.map +1 -0
- package/esm/errors/tool-execution-error.d.mts +35 -0
- package/esm/errors/tool-execution-error.d.mts.map +1 -0
- package/esm/errors/tool-execution-error.mjs +32 -0
- package/esm/errors/tool-execution-error.mjs.map +1 -0
- package/esm/errors/workflow-cancelled-error.d.mts +23 -0
- package/esm/errors/workflow-cancelled-error.d.mts.map +1 -0
- package/esm/errors/workflow-cancelled-error.mjs +23 -0
- package/esm/errors/workflow-cancelled-error.mjs.map +1 -0
- package/esm/errors/workflow-drift-error.d.mts +25 -0
- package/esm/errors/workflow-drift-error.d.mts.map +1 -0
- package/esm/errors/workflow-drift-error.mjs +24 -0
- package/esm/errors/workflow-drift-error.mjs.map +1 -0
- package/esm/errors/workflow-error.d.mts +15 -0
- package/esm/errors/workflow-error.d.mts.map +1 -0
- package/esm/errors/workflow-error.mjs +18 -0
- package/esm/errors/workflow-error.mjs.map +1 -0
- package/esm/index.d.mts +137 -0
- package/esm/index.mjs +81 -0
- package/esm/middleware/builtins/budget.d.mts +103 -0
- package/esm/middleware/builtins/budget.d.mts.map +1 -0
- package/esm/middleware/builtins/budget.mjs +100 -0
- package/esm/middleware/builtins/budget.mjs.map +1 -0
- package/esm/middleware/builtins/guardrail.d.mts +92 -0
- package/esm/middleware/builtins/guardrail.d.mts.map +1 -0
- package/esm/middleware/builtins/guardrail.mjs +76 -0
- package/esm/middleware/builtins/guardrail.mjs.map +1 -0
- package/esm/middleware/builtins/semantic-cache.d.mts +106 -0
- package/esm/middleware/builtins/semantic-cache.d.mts.map +1 -0
- package/esm/middleware/builtins/semantic-cache.mjs +149 -0
- package/esm/middleware/builtins/semantic-cache.mjs.map +1 -0
- package/esm/middleware/helpers/compose.d.mts +42 -0
- package/esm/middleware/helpers/compose.d.mts.map +1 -0
- package/esm/middleware/helpers/compose.mjs +52 -0
- package/esm/middleware/helpers/compose.mjs.map +1 -0
- package/esm/middleware/helpers/for-tool.d.mts +55 -0
- package/esm/middleware/helpers/for-tool.d.mts.map +1 -0
- package/esm/middleware/helpers/for-tool.mjs +80 -0
- package/esm/middleware/helpers/for-tool.mjs.map +1 -0
- package/esm/middleware/helpers/index.d.mts +2 -0
- package/esm/middleware/index.d.mts +8 -0
- package/esm/middleware/index.mjs +10 -0
- package/esm/middleware/pipeline.d.mts +70 -0
- package/esm/middleware/pipeline.d.mts.map +1 -0
- package/esm/middleware/pipeline.mjs +100 -0
- package/esm/middleware/pipeline.mjs.map +1 -0
- package/esm/middleware/utils/extract-user-text.d.mts +33 -0
- package/esm/middleware/utils/extract-user-text.d.mts.map +1 -0
- package/esm/middleware/utils/extract-user-text.mjs +40 -0
- package/esm/middleware/utils/extract-user-text.mjs.map +1 -0
- package/esm/middleware/utils/index.d.mts +2 -0
- package/esm/middleware/utils/namespaced-state.d.mts +60 -0
- package/esm/middleware/utils/namespaced-state.d.mts.map +1 -0
- package/esm/middleware/utils/namespaced-state.mjs +60 -0
- package/esm/middleware/utils/namespaced-state.mjs.map +1 -0
- package/esm/mock/index.d.mts +4 -0
- package/esm/mock/index.mjs +5 -0
- package/esm/mock/mock-agent.d.mts +41 -0
- package/esm/mock/mock-agent.d.mts.map +1 -0
- package/esm/mock/mock-agent.mjs +39 -0
- package/esm/mock/mock-agent.mjs.map +1 -0
- package/esm/mock/mock-config.type.d.mts +31 -0
- package/esm/mock/mock-config.type.d.mts.map +1 -0
- package/esm/mock/mock-model.d.mts +94 -0
- package/esm/mock/mock-model.d.mts.map +1 -0
- package/esm/mock/mock-model.mjs +150 -0
- package/esm/mock/mock-model.mjs.map +1 -0
- package/esm/mock/mock-sdk.d.mts +25 -0
- package/esm/mock/mock-sdk.d.mts.map +1 -0
- package/esm/mock/mock-sdk.mjs +37 -0
- package/esm/mock/mock-sdk.mjs.map +1 -0
- package/esm/supervisor/as-tool.d.mts +45 -0
- package/esm/supervisor/as-tool.d.mts.map +1 -0
- package/esm/supervisor/as-tool.mjs +80 -0
- package/esm/supervisor/as-tool.mjs.map +1 -0
- package/esm/supervisor/cancellation.d.mts +12 -0
- package/esm/supervisor/cancellation.d.mts.map +1 -0
- package/esm/supervisor/cancellation.mjs +22 -0
- package/esm/supervisor/cancellation.mjs.map +1 -0
- package/esm/supervisor/decide.mjs +272 -0
- package/esm/supervisor/decide.mjs.map +1 -0
- package/esm/supervisor/emitter.d.mts +27 -0
- package/esm/supervisor/emitter.d.mts.map +1 -0
- package/esm/supervisor/emitter.mjs +47 -0
- package/esm/supervisor/emitter.mjs.map +1 -0
- package/esm/supervisor/entries.d.mts +141 -0
- package/esm/supervisor/entries.d.mts.map +1 -0
- package/esm/supervisor/entries.mjs +206 -0
- package/esm/supervisor/entries.mjs.map +1 -0
- package/esm/supervisor/execution.d.mts +637 -0
- package/esm/supervisor/execution.d.mts.map +1 -0
- package/esm/supervisor/execution.mjs +1868 -0
- package/esm/supervisor/execution.mjs.map +1 -0
- package/esm/supervisor/index.d.mts +11 -0
- package/esm/supervisor/index.mjs +12 -0
- package/esm/supervisor/router-prompt.d.mts +56 -0
- package/esm/supervisor/router-prompt.d.mts.map +1 -0
- package/esm/supervisor/router-prompt.mjs +52 -0
- package/esm/supervisor/router-prompt.mjs.map +1 -0
- package/esm/supervisor/signature.d.mts +28 -0
- package/esm/supervisor/signature.d.mts.map +1 -0
- package/esm/supervisor/signature.mjs +89 -0
- package/esm/supervisor/signature.mjs.map +1 -0
- package/esm/supervisor/snapshot.d.mts +54 -0
- package/esm/supervisor/snapshot.d.mts.map +1 -0
- package/esm/supervisor/snapshot.mjs +77 -0
- package/esm/supervisor/snapshot.mjs.map +1 -0
- package/esm/supervisor/supervisor-stream.d.mts +29 -0
- package/esm/supervisor/supervisor-stream.d.mts.map +1 -0
- package/esm/supervisor/supervisor-stream.mjs +89 -0
- package/esm/supervisor/supervisor-stream.mjs.map +1 -0
- package/esm/supervisor/supervisor.d.mts +27 -0
- package/esm/supervisor/supervisor.d.mts.map +1 -0
- package/esm/supervisor/supervisor.mjs +138 -0
- package/esm/supervisor/supervisor.mjs.map +1 -0
- package/esm/system-prompt/instruction.d.mts +52 -0
- package/esm/system-prompt/instruction.d.mts.map +1 -0
- package/esm/system-prompt/instruction.mjs +57 -0
- package/esm/system-prompt/instruction.mjs.map +1 -0
- package/esm/system-prompt/persona.d.mts +52 -0
- package/esm/system-prompt/persona.d.mts.map +1 -0
- package/esm/system-prompt/persona.mjs +57 -0
- package/esm/system-prompt/persona.mjs.map +1 -0
- package/esm/system-prompt/render-placeholders.d.mts +31 -0
- package/esm/system-prompt/render-placeholders.d.mts.map +1 -0
- package/esm/system-prompt/render-placeholders.mjs +58 -0
- package/esm/system-prompt/render-placeholders.mjs.map +1 -0
- package/esm/system-prompt/system-prompt.d.mts +117 -0
- package/esm/system-prompt/system-prompt.d.mts.map +1 -0
- package/esm/system-prompt/system-prompt.mjs +137 -0
- package/esm/system-prompt/system-prompt.mjs.map +1 -0
- package/esm/tool/index.d.mts +1 -0
- package/esm/tool/index.mjs +3 -0
- package/esm/tool/tool.d.mts +64 -0
- package/esm/tool/tool.d.mts.map +1 -0
- package/esm/tool/tool.mjs +184 -0
- package/esm/tool/tool.mjs.map +1 -0
- package/esm/utils/compute-cost.d.mts +58 -0
- package/esm/utils/compute-cost.d.mts.map +1 -0
- package/esm/utils/compute-cost.mjs +87 -0
- package/esm/utils/compute-cost.mjs.map +1 -0
- package/esm/utils/extract-json-payload.d.mts +33 -0
- package/esm/utils/extract-json-payload.d.mts.map +1 -0
- package/esm/utils/extract-json-payload.mjs +39 -0
- package/esm/utils/extract-json-payload.mjs.map +1 -0
- package/esm/utils/generate-run-id.d.mts +20 -0
- package/esm/utils/generate-run-id.d.mts.map +1 -0
- package/esm/utils/generate-run-id.mjs +23 -0
- package/esm/utils/generate-run-id.mjs.map +1 -0
- package/esm/utils/index.d.mts +9 -0
- package/esm/utils/index.mjs +11 -0
- package/esm/utils/json-schema.d.mts +57 -0
- package/esm/utils/json-schema.d.mts.map +1 -0
- package/esm/utils/json-schema.mjs +89 -0
- package/esm/utils/json-schema.mjs.map +1 -0
- package/esm/utils/prepare-attachment-part.d.mts +36 -0
- package/esm/utils/prepare-attachment-part.d.mts.map +1 -0
- package/esm/utils/prepare-attachment-part.mjs +140 -0
- package/esm/utils/prepare-attachment-part.mjs.map +1 -0
- package/esm/utils/resolve-attachment.d.mts +33 -0
- package/esm/utils/resolve-attachment.d.mts.map +1 -0
- package/esm/utils/resolve-attachment.mjs +73 -0
- package/esm/utils/resolve-attachment.mjs.map +1 -0
- package/esm/utils/safe-json-parse.d.mts +14 -0
- package/esm/utils/safe-json-parse.d.mts.map +1 -0
- package/esm/utils/safe-json-parse.mjs +22 -0
- package/esm/utils/safe-json-parse.mjs.map +1 -0
- package/esm/utils/stamp-report-lineage.d.mts +61 -0
- package/esm/utils/stamp-report-lineage.d.mts.map +1 -0
- package/esm/utils/stamp-report-lineage.mjs +47 -0
- package/esm/utils/stamp-report-lineage.mjs.map +1 -0
- package/esm/utils/token-count.d.mts +15 -0
- package/esm/utils/token-count.d.mts.map +1 -0
- package/esm/utils/token-count.mjs +18 -0
- package/esm/utils/token-count.mjs.map +1 -0
- package/esm/workflow/as-tool.mjs +55 -0
- package/esm/workflow/as-tool.mjs.map +1 -0
- package/esm/workflow/cancellation.mjs +44 -0
- package/esm/workflow/cancellation.mjs.map +1 -0
- package/esm/workflow/emitter.mjs +40 -0
- package/esm/workflow/emitter.mjs.map +1 -0
- package/esm/workflow/engine.mjs +362 -0
- package/esm/workflow/engine.mjs.map +1 -0
- package/esm/workflow/index.d.mts +3 -0
- package/esm/workflow/index.mjs +5 -0
- package/esm/workflow/retry.mjs +32 -0
- package/esm/workflow/retry.mjs.map +1 -0
- package/esm/workflow/router.mjs +56 -0
- package/esm/workflow/router.mjs.map +1 -0
- package/esm/workflow/run-scoped-emitter.mjs +32 -0
- package/esm/workflow/run-scoped-emitter.mjs.map +1 -0
- package/esm/workflow/signature.d.mts +7 -0
- package/esm/workflow/signature.d.mts.map +1 -0
- package/esm/workflow/signature.mjs +34 -0
- package/esm/workflow/signature.mjs.map +1 -0
- package/esm/workflow/snapshot.mjs +71 -0
- package/esm/workflow/snapshot.mjs.map +1 -0
- package/esm/workflow/state.mjs +37 -0
- package/esm/workflow/state.mjs.map +1 -0
- package/esm/workflow/step-runner.mjs +371 -0
- package/esm/workflow/step-runner.mjs.map +1 -0
- package/esm/workflow/step.d.mts +19 -0
- package/esm/workflow/step.d.mts.map +1 -0
- package/esm/workflow/step.mjs +37 -0
- package/esm/workflow/step.mjs.map +1 -0
- package/esm/workflow/workflow.d.mts +12 -0
- package/esm/workflow/workflow.d.mts.map +1 -0
- package/esm/workflow/workflow.mjs +116 -0
- package/esm/workflow/workflow.mjs.map +1 -0
- package/llms-full.txt +2293 -0
- package/llms.txt +20 -0
- package/package.json +37 -0
- package/skills/README.md +53 -0
- package/skills/ai-basics/SKILL.md +95 -0
- package/skills/attach-ai-middleware/SKILL.md +184 -0
- package/skills/define-ai-tool/SKILL.md +186 -0
- package/skills/embed-text/SKILL.md +105 -0
- package/skills/handle-ai-errors/SKILL.md +194 -0
- package/skills/log-ai-calls/SKILL.md +141 -0
- package/skills/persist-ai-data/SKILL.md +207 -0
- package/skills/pick-ai-provider/SKILL.md +164 -0
- package/skills/run-ai-agent/SKILL.md +267 -0
- package/skills/run-ai-workflow/SKILL.md +258 -0
- package/skills/run-supervisor/SKILL.md +309 -0
- package/skills/write-system-prompt/SKILL.md +129 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { renderPlaceholders } from "./render-placeholders.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../@warlock.js/ai/src/system-prompt/instruction.ts
|
|
4
|
+
/**
|
|
5
|
+
* Concrete `InstructionContract` — a reusable directive block.
|
|
6
|
+
*
|
|
7
|
+
* **Role.** A single addressable prompt block representing one rule the
|
|
8
|
+
* agent must follow (`"Always respond in {{language|English}}."`). Exists
|
|
9
|
+
* as its own type so the same instruction can be shared across many
|
|
10
|
+
* prompts and agents, each render supplying its own placeholder map.
|
|
11
|
+
*
|
|
12
|
+
* **Responsibility.**
|
|
13
|
+
* - Owns: the `type: "instruction"` discriminator, the raw template text,
|
|
14
|
+
* and the placeholder-rendering step.
|
|
15
|
+
* - Does NOT own: ordering relative to other instructions, joining with a
|
|
16
|
+
* persona, or any surrounding prompt composition — those concerns live
|
|
17
|
+
* in `SystemPrompt`.
|
|
18
|
+
*
|
|
19
|
+
* Users construct via the `ai.instruction()` factory — `new Instruction()`
|
|
20
|
+
* is not the public API (see §4.2 of code-style.md).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const replyInLanguage = ai.instruction("Respond in {{language|English}}.");
|
|
24
|
+
*
|
|
25
|
+
* const prompt = ai.systemPrompt()
|
|
26
|
+
* .persona("You are Alex.")
|
|
27
|
+
* .instruction(replyInLanguage)
|
|
28
|
+
* .instruction("Always include code examples.");
|
|
29
|
+
*/
|
|
30
|
+
var Instruction = class {
|
|
31
|
+
constructor(text) {
|
|
32
|
+
this.text = text;
|
|
33
|
+
this.type = "instruction";
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Substitute `{{mustache}}` placeholders in the instruction text against
|
|
37
|
+
* the supplied map. Delegates to the shared `renderPlaceholders` helper
|
|
38
|
+
* so persona / instruction / system-prompt rendering stays identical.
|
|
39
|
+
*/
|
|
40
|
+
resolve(placeholders) {
|
|
41
|
+
return renderPlaceholders(this.text, placeholders);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Create an `Instruction` from raw template text.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const replyIn = instruction("Respond in {{language|English}}.");
|
|
49
|
+
* const cite = instruction("Always cite sources inline.");
|
|
50
|
+
*/
|
|
51
|
+
function instruction(text) {
|
|
52
|
+
return new Instruction(text);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { Instruction, instruction };
|
|
57
|
+
//# sourceMappingURL=instruction.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instruction.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/system-prompt/instruction.ts"],"sourcesContent":["import type { Placeholders } from \"../contracts/placeholders.type\";\nimport type { InstructionContract } from \"../contracts/system-prompt.contract\";\nimport { renderPlaceholders } from \"./render-placeholders\";\n\n/**\n * Concrete `InstructionContract` — a reusable directive block.\n *\n * **Role.** A single addressable prompt block representing one rule the\n * agent must follow (`\"Always respond in {{language|English}}.\"`). Exists\n * as its own type so the same instruction can be shared across many\n * prompts and agents, each render supplying its own placeholder map.\n *\n * **Responsibility.**\n * - Owns: the `type: \"instruction\"` discriminator, the raw template text,\n * and the placeholder-rendering step.\n * - Does NOT own: ordering relative to other instructions, joining with a\n * persona, or any surrounding prompt composition — those concerns live\n * in `SystemPrompt`.\n *\n * Users construct via the `ai.instruction()` factory — `new Instruction()`\n * is not the public API (see §4.2 of code-style.md).\n *\n * @example\n * const replyInLanguage = ai.instruction(\"Respond in {{language|English}}.\");\n *\n * const prompt = ai.systemPrompt()\n * .persona(\"You are Alex.\")\n * .instruction(replyInLanguage)\n * .instruction(\"Always include code examples.\");\n */\nexport class Instruction implements InstructionContract {\n public readonly type = \"instruction\" as const;\n\n public constructor(public readonly text: string) {\n //\n }\n\n /**\n * Substitute `{{mustache}}` placeholders in the instruction text against\n * the supplied map. Delegates to the shared `renderPlaceholders` helper\n * so persona / instruction / system-prompt rendering stays identical.\n */\n public resolve(placeholders?: Placeholders): string {\n return renderPlaceholders(this.text, placeholders);\n }\n}\n\n/**\n * Create an `Instruction` from raw template text.\n *\n * @example\n * const replyIn = instruction(\"Respond in {{language|English}}.\");\n * const cite = instruction(\"Always cite sources inline.\");\n */\nexport function instruction(text: string): Instruction {\n return new Instruction(text);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAa,cAAb,MAAwD;CAGtD,AAAO,YAAY,AAAgB,MAAc;EAAd;cAFZ;CAIvB;;;;;;CAOA,AAAO,QAAQ,cAAqC;EAClD,OAAO,mBAAmB,KAAK,MAAM,YAAY;CACnD;AACF;;;;;;;;AASA,SAAgB,YAAY,MAA2B;CACrD,OAAO,IAAI,YAAY,IAAI;AAC7B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Placeholders } from "../contracts/placeholders.type.mjs";
|
|
2
|
+
import { PersonaContract } from "../contracts/system-prompt.contract.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../../@warlock.js/ai/src/system-prompt/persona.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Concrete `PersonaContract` — a reusable "who the agent is" block.
|
|
7
|
+
*
|
|
8
|
+
* **Role.** A single addressable prompt block representing the agent's
|
|
9
|
+
* identity (`"You are Alex, a senior TypeScript engineer."`). Exists as
|
|
10
|
+
* its own type so personas can be defined once and reused across many
|
|
11
|
+
* `SystemPrompt` compositions, agents, and sessions — each render can
|
|
12
|
+
* supply a different placeholder map.
|
|
13
|
+
*
|
|
14
|
+
* **Responsibility.**
|
|
15
|
+
* - Owns: the `type: "persona"` discriminator, the raw template text, and
|
|
16
|
+
* the placeholder-rendering step.
|
|
17
|
+
* - Does NOT own: composition with instructions, ordering, joining, or
|
|
18
|
+
* any knowledge of the surrounding `SystemPrompt`. Those concerns live
|
|
19
|
+
* in `SystemPrompt`.
|
|
20
|
+
*
|
|
21
|
+
* Users construct via the `ai.persona()` factory — `new Persona()` is not
|
|
22
|
+
* the public API (see §4.2 of code-style.md).
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const alex = ai.persona("You are Alex, a TypeScript expert.");
|
|
26
|
+
*
|
|
27
|
+
* const prompt = ai.systemPrompt()
|
|
28
|
+
* .persona(alex)
|
|
29
|
+
* .instruction("Always cite sources.");
|
|
30
|
+
*/
|
|
31
|
+
declare class Persona implements PersonaContract {
|
|
32
|
+
readonly text: string;
|
|
33
|
+
readonly type: "persona";
|
|
34
|
+
constructor(text: string);
|
|
35
|
+
/**
|
|
36
|
+
* Substitute `{{mustache}}` placeholders in the persona text against the
|
|
37
|
+
* supplied map. Delegates to the shared `renderPlaceholders` helper so
|
|
38
|
+
* persona / instruction / system-prompt rendering stays identical.
|
|
39
|
+
*/
|
|
40
|
+
resolve(placeholders?: Placeholders): string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create a `Persona` from raw template text.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const alex = persona("You are Alex, a TypeScript expert.");
|
|
47
|
+
* const greeter = persona("You are a greeter in {{language|English}}.");
|
|
48
|
+
*/
|
|
49
|
+
declare function persona(text: string): Persona;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { Persona, persona };
|
|
52
|
+
//# sourceMappingURL=persona.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persona.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/system-prompt/persona.ts"],"mappings":";;;;;;AA8BA;;;;;;;;;;;;;AAY4C;AAY5C;;;;AAA8C;;;;;;cAxBjC,OAAA,YAAmB,eAAe;EAAA,SAGV,IAAA;EAAA,SAFnB,IAAA;cAEmB,IAAA;;;;;;EAS5B,OAAA,CAAQ,YAAA,GAAe,YAAA;AAAA;;;;;;;;iBAYhB,OAAA,CAAQ,IAAA,WAAe,OAAO"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { renderPlaceholders } from "./render-placeholders.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../@warlock.js/ai/src/system-prompt/persona.ts
|
|
4
|
+
/**
|
|
5
|
+
* Concrete `PersonaContract` — a reusable "who the agent is" block.
|
|
6
|
+
*
|
|
7
|
+
* **Role.** A single addressable prompt block representing the agent's
|
|
8
|
+
* identity (`"You are Alex, a senior TypeScript engineer."`). Exists as
|
|
9
|
+
* its own type so personas can be defined once and reused across many
|
|
10
|
+
* `SystemPrompt` compositions, agents, and sessions — each render can
|
|
11
|
+
* supply a different placeholder map.
|
|
12
|
+
*
|
|
13
|
+
* **Responsibility.**
|
|
14
|
+
* - Owns: the `type: "persona"` discriminator, the raw template text, and
|
|
15
|
+
* the placeholder-rendering step.
|
|
16
|
+
* - Does NOT own: composition with instructions, ordering, joining, or
|
|
17
|
+
* any knowledge of the surrounding `SystemPrompt`. Those concerns live
|
|
18
|
+
* in `SystemPrompt`.
|
|
19
|
+
*
|
|
20
|
+
* Users construct via the `ai.persona()` factory — `new Persona()` is not
|
|
21
|
+
* the public API (see §4.2 of code-style.md).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const alex = ai.persona("You are Alex, a TypeScript expert.");
|
|
25
|
+
*
|
|
26
|
+
* const prompt = ai.systemPrompt()
|
|
27
|
+
* .persona(alex)
|
|
28
|
+
* .instruction("Always cite sources.");
|
|
29
|
+
*/
|
|
30
|
+
var Persona = class {
|
|
31
|
+
constructor(text) {
|
|
32
|
+
this.text = text;
|
|
33
|
+
this.type = "persona";
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Substitute `{{mustache}}` placeholders in the persona text against the
|
|
37
|
+
* supplied map. Delegates to the shared `renderPlaceholders` helper so
|
|
38
|
+
* persona / instruction / system-prompt rendering stays identical.
|
|
39
|
+
*/
|
|
40
|
+
resolve(placeholders) {
|
|
41
|
+
return renderPlaceholders(this.text, placeholders);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Create a `Persona` from raw template text.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const alex = persona("You are Alex, a TypeScript expert.");
|
|
49
|
+
* const greeter = persona("You are a greeter in {{language|English}}.");
|
|
50
|
+
*/
|
|
51
|
+
function persona(text) {
|
|
52
|
+
return new Persona(text);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { Persona, persona };
|
|
57
|
+
//# sourceMappingURL=persona.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persona.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/system-prompt/persona.ts"],"sourcesContent":["import type { Placeholders } from \"../contracts/placeholders.type\";\nimport type { PersonaContract } from \"../contracts/system-prompt.contract\";\nimport { renderPlaceholders } from \"./render-placeholders\";\n\n/**\n * Concrete `PersonaContract` — a reusable \"who the agent is\" block.\n *\n * **Role.** A single addressable prompt block representing the agent's\n * identity (`\"You are Alex, a senior TypeScript engineer.\"`). Exists as\n * its own type so personas can be defined once and reused across many\n * `SystemPrompt` compositions, agents, and sessions — each render can\n * supply a different placeholder map.\n *\n * **Responsibility.**\n * - Owns: the `type: \"persona\"` discriminator, the raw template text, and\n * the placeholder-rendering step.\n * - Does NOT own: composition with instructions, ordering, joining, or\n * any knowledge of the surrounding `SystemPrompt`. Those concerns live\n * in `SystemPrompt`.\n *\n * Users construct via the `ai.persona()` factory — `new Persona()` is not\n * the public API (see §4.2 of code-style.md).\n *\n * @example\n * const alex = ai.persona(\"You are Alex, a TypeScript expert.\");\n *\n * const prompt = ai.systemPrompt()\n * .persona(alex)\n * .instruction(\"Always cite sources.\");\n */\nexport class Persona implements PersonaContract {\n public readonly type = \"persona\" as const;\n\n public constructor(public readonly text: string) {\n //\n }\n\n /**\n * Substitute `{{mustache}}` placeholders in the persona text against the\n * supplied map. Delegates to the shared `renderPlaceholders` helper so\n * persona / instruction / system-prompt rendering stays identical.\n */\n public resolve(placeholders?: Placeholders): string {\n return renderPlaceholders(this.text, placeholders);\n }\n}\n\n/**\n * Create a `Persona` from raw template text.\n *\n * @example\n * const alex = persona(\"You are Alex, a TypeScript expert.\");\n * const greeter = persona(\"You are a greeter in {{language|English}}.\");\n */\nexport function persona(text: string): Persona {\n return new Persona(text);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAa,UAAb,MAAgD;CAG9C,AAAO,YAAY,AAAgB,MAAc;EAAd;cAFZ;CAIvB;;;;;;CAOA,AAAO,QAAQ,cAAqC;EAClD,OAAO,mBAAmB,KAAK,MAAM,YAAY;CACnD;AACF;;;;;;;;AASA,SAAgB,QAAQ,MAAuB;CAC7C,OAAO,IAAI,QAAQ,IAAI;AACzB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Placeholders } from "../contracts/placeholders.type.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../@warlock.js/ai/src/system-prompt/render-placeholders.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Render a template string against a placeholders map, supporting dot-path
|
|
6
|
+
* lookups and inline fallback values.
|
|
7
|
+
*
|
|
8
|
+
* Supported syntax:
|
|
9
|
+
* - `{{key}}` — replaced by `placeholders.key`, left untouched if missing.
|
|
10
|
+
* - `{{a.b.c}}` — dot-path lookup into nested objects.
|
|
11
|
+
* - `{{key|default}}` — substitutes `default` when the key resolves to
|
|
12
|
+
* `undefined`, `null`, or empty string.
|
|
13
|
+
*
|
|
14
|
+
* Whitespace inside the braces is ignored (`{{ key }}` == `{{key}}`).
|
|
15
|
+
* Values are coerced to strings via `String(value)`.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* renderPlaceholders(
|
|
19
|
+
* "Hello {{user.name|friend}}, your role is {{role}}",
|
|
20
|
+
* { user: { name: "Hasan" }, role: "admin" },
|
|
21
|
+
* );
|
|
22
|
+
* // "Hello Hasan, your role is admin"
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* renderPlaceholders("Hello {{user.name|friend}}", {});
|
|
26
|
+
* // "Hello friend"
|
|
27
|
+
*/
|
|
28
|
+
declare function renderPlaceholders(template: string, placeholders?: Placeholders): string;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { renderPlaceholders };
|
|
31
|
+
//# sourceMappingURL=render-placeholders.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-placeholders.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/system-prompt/render-placeholders.ts"],"mappings":";;;;;AA4BA;;;;;;;;AAEiC;;;;;;;;;;;;;;iBAFjB,kBAAA,CACd,QAAA,UACA,YAAA,GAAc,YAAiB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//#region ../../@warlock.js/ai/src/system-prompt/render-placeholders.ts
|
|
2
|
+
const PLACEHOLDER_PATTERN = /\{\{\s*([^{}]+?)\s*\}\}/g;
|
|
3
|
+
/**
|
|
4
|
+
* Render a template string against a placeholders map, supporting dot-path
|
|
5
|
+
* lookups and inline fallback values.
|
|
6
|
+
*
|
|
7
|
+
* Supported syntax:
|
|
8
|
+
* - `{{key}}` — replaced by `placeholders.key`, left untouched if missing.
|
|
9
|
+
* - `{{a.b.c}}` — dot-path lookup into nested objects.
|
|
10
|
+
* - `{{key|default}}` — substitutes `default` when the key resolves to
|
|
11
|
+
* `undefined`, `null`, or empty string.
|
|
12
|
+
*
|
|
13
|
+
* Whitespace inside the braces is ignored (`{{ key }}` == `{{key}}`).
|
|
14
|
+
* Values are coerced to strings via `String(value)`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* renderPlaceholders(
|
|
18
|
+
* "Hello {{user.name|friend}}, your role is {{role}}",
|
|
19
|
+
* { user: { name: "Hasan" }, role: "admin" },
|
|
20
|
+
* );
|
|
21
|
+
* // "Hello Hasan, your role is admin"
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* renderPlaceholders("Hello {{user.name|friend}}", {});
|
|
25
|
+
* // "Hello friend"
|
|
26
|
+
*/
|
|
27
|
+
function renderPlaceholders(template, placeholders = {}) {
|
|
28
|
+
return template.replace(PLACEHOLDER_PATTERN, (match, rawExpression) => {
|
|
29
|
+
const [rawPath, rawFallback] = rawExpression.split("|");
|
|
30
|
+
const path = rawPath.trim();
|
|
31
|
+
const fallback = rawFallback?.trim();
|
|
32
|
+
const value = lookupPath(placeholders, path);
|
|
33
|
+
if (value === void 0 || value === null || value === "") {
|
|
34
|
+
if (fallback !== void 0) return fallback;
|
|
35
|
+
return match;
|
|
36
|
+
}
|
|
37
|
+
return String(value);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Walk a dot-path (`"a.b.c"`) through an arbitrary record, returning the
|
|
42
|
+
* leaf value or `undefined` when any segment is missing or blocks traversal
|
|
43
|
+
* (non-object). Never throws.
|
|
44
|
+
*/
|
|
45
|
+
function lookupPath(source, path) {
|
|
46
|
+
const segments = path.split(".");
|
|
47
|
+
let current = source;
|
|
48
|
+
for (const segment of segments) {
|
|
49
|
+
if (current === null || current === void 0) return;
|
|
50
|
+
if (typeof current !== "object") return;
|
|
51
|
+
current = current[segment];
|
|
52
|
+
}
|
|
53
|
+
return current;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { renderPlaceholders };
|
|
58
|
+
//# sourceMappingURL=render-placeholders.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-placeholders.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/system-prompt/render-placeholders.ts"],"sourcesContent":["import type { Placeholders } from \"../contracts/placeholders.type\";\n\nconst PLACEHOLDER_PATTERN = /\\{\\{\\s*([^{}]+?)\\s*\\}\\}/g;\n\n/**\n * Render a template string against a placeholders map, supporting dot-path\n * lookups and inline fallback values.\n *\n * Supported syntax:\n * - `{{key}}` — replaced by `placeholders.key`, left untouched if missing.\n * - `{{a.b.c}}` — dot-path lookup into nested objects.\n * - `{{key|default}}` — substitutes `default` when the key resolves to\n * `undefined`, `null`, or empty string.\n *\n * Whitespace inside the braces is ignored (`{{ key }}` == `{{key}}`).\n * Values are coerced to strings via `String(value)`.\n *\n * @example\n * renderPlaceholders(\n * \"Hello {{user.name|friend}}, your role is {{role}}\",\n * { user: { name: \"Hasan\" }, role: \"admin\" },\n * );\n * // \"Hello Hasan, your role is admin\"\n *\n * @example\n * renderPlaceholders(\"Hello {{user.name|friend}}\", {});\n * // \"Hello friend\"\n */\nexport function renderPlaceholders(\n template: string,\n placeholders: Placeholders = {},\n): string {\n return template.replace(\n PLACEHOLDER_PATTERN,\n (match, rawExpression: string) => {\n const [rawPath, rawFallback] = rawExpression.split(\"|\");\n const path = rawPath.trim();\n const fallback = rawFallback?.trim();\n\n const value = lookupPath(placeholders, path);\n\n if (value === undefined || value === null || value === \"\") {\n if (fallback !== undefined) {\n return fallback;\n }\n\n return match;\n }\n\n return String(value);\n },\n );\n}\n\n/**\n * Walk a dot-path (`\"a.b.c\"`) through an arbitrary record, returning the\n * leaf value or `undefined` when any segment is missing or blocks traversal\n * (non-object). Never throws.\n */\nfunction lookupPath(source: Placeholders, path: string): unknown {\n const segments = path.split(\".\");\n let current: unknown = source;\n\n for (const segment of segments) {\n if (current === null || current === undefined) {\n return undefined;\n }\n\n if (typeof current !== \"object\") {\n return undefined;\n }\n\n current = (current as Record<string, unknown>)[segment];\n }\n\n return current;\n}\n"],"mappings":";AAEA,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;AA0B5B,SAAgB,mBACd,UACA,eAA6B,CAAC,GACtB;CACR,OAAO,SAAS,QACd,sBACC,OAAO,kBAA0B;EAChC,MAAM,CAAC,SAAS,eAAe,cAAc,MAAM,GAAG;EACtD,MAAM,OAAO,QAAQ,KAAK;EAC1B,MAAM,WAAW,aAAa,KAAK;EAEnC,MAAM,QAAQ,WAAW,cAAc,IAAI;EAE3C,IAAI,UAAU,UAAa,UAAU,QAAQ,UAAU,IAAI;GACzD,IAAI,aAAa,QACf,OAAO;GAGT,OAAO;EACT;EAEA,OAAO,OAAO,KAAK;CACrB,CACF;AACF;;;;;;AAOA,SAAS,WAAW,QAAsB,MAAuB;CAC/D,MAAM,WAAW,KAAK,MAAM,GAAG;CAC/B,IAAI,UAAmB;CAEvB,KAAK,MAAM,WAAW,UAAU;EAC9B,IAAI,YAAY,QAAQ,YAAY,QAClC;EAGF,IAAI,OAAO,YAAY,UACrB;EAGF,UAAW,QAAoC;CACjD;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Placeholders } from "../contracts/placeholders.type.mjs";
|
|
2
|
+
import { InstructionContract, PersonaContract, SystemPromptBlockContract, SystemPromptContract } from "../contracts/system-prompt.contract.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../../@warlock.js/ai/src/system-prompt/system-prompt.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Concrete `SystemPromptContract` — an immutable layered prompt builder.
|
|
7
|
+
*
|
|
8
|
+
* **Role.** The top-level composer for a system prompt: it holds an ordered
|
|
9
|
+
* list of typed blocks (persona + instructions) and resolves the whole
|
|
10
|
+
* stack into one final string when the agent is about to call the model.
|
|
11
|
+
*
|
|
12
|
+
* **Responsibility.**
|
|
13
|
+
* - Owns: the ordered `blocks` list and the block-join rules (insertion
|
|
14
|
+
* order, blank-line separator, trim).
|
|
15
|
+
* - Does NOT own: how any individual block is rendered (delegated to each
|
|
16
|
+
* block's `resolve()`), the placeholder syntax (delegated to
|
|
17
|
+
* `renderPlaceholders`), or any knowledge of the agent, model, or
|
|
18
|
+
* session consuming the resolved text.
|
|
19
|
+
*
|
|
20
|
+
* Blocks are discriminated by a string `type` tag (`"persona"` /
|
|
21
|
+
* `"instruction"`) rather than `instanceof`, so user-supplied blocks that
|
|
22
|
+
* implement `SystemPromptBlockContract` interoperate seamlessly with blocks
|
|
23
|
+
* built via `ai.persona()` / `ai.instruction()` — even across duplicate
|
|
24
|
+
* package copies or bundler scope boundaries.
|
|
25
|
+
*
|
|
26
|
+
* The builder is **immutable** — every `.persona()` / `.instruction()`
|
|
27
|
+
* call returns a fresh `SystemPrompt` instance sharing nothing mutable
|
|
28
|
+
* with its parent. This makes forking a base prompt into specialized
|
|
29
|
+
* variants a safe, side-effect-free operation.
|
|
30
|
+
*
|
|
31
|
+
* Users construct via the `ai.systemPrompt()` factory — `new SystemPrompt()`
|
|
32
|
+
* is not the public API (see §4.2 of code-style.md). Modeled as a class so
|
|
33
|
+
* that methods live on the prototype (one copy shared across every forked
|
|
34
|
+
* instance) and downstream code can branch via `instanceof SystemPrompt`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // Chainable form
|
|
38
|
+
* const alex = ai.persona("You are Alex, a TypeScript expert.");
|
|
39
|
+
* const replyIn = ai.instruction("Respond in {{language|English}}.");
|
|
40
|
+
*
|
|
41
|
+
* const base = ai.systemPrompt().persona(alex).instruction(replyIn);
|
|
42
|
+
* const arabicVariant = base.instruction("Prefer Arabic comments.");
|
|
43
|
+
*
|
|
44
|
+
* base.resolve({ language: "English" });
|
|
45
|
+
* arabicVariant.resolve({ language: "Arabic" });
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // Array form — insertion order is preserved exactly
|
|
49
|
+
* const prompt = ai.systemPrompt([
|
|
50
|
+
* ai.persona("You are Alex, a TypeScript expert."),
|
|
51
|
+
* ai.instruction("Respond in {{language|English}}."),
|
|
52
|
+
* ]);
|
|
53
|
+
*/
|
|
54
|
+
declare class SystemPrompt implements SystemPromptContract {
|
|
55
|
+
readonly blocks: readonly SystemPromptBlockContract[];
|
|
56
|
+
constructor(blocks?: readonly SystemPromptBlockContract[]);
|
|
57
|
+
/**
|
|
58
|
+
* Return a new builder with the persona block set. If a persona already
|
|
59
|
+
* exists it's replaced in place (preserving its position in `blocks`);
|
|
60
|
+
* otherwise the new persona is prepended so persona-first remains the
|
|
61
|
+
* default for chain-built prompts. Accepts either raw text (auto-wrapped
|
|
62
|
+
* via `new Persona`) or an existing `PersonaContract` instance for reuse
|
|
63
|
+
* across prompts.
|
|
64
|
+
*/
|
|
65
|
+
persona(value: PersonaContract | string): SystemPromptContract;
|
|
66
|
+
/**
|
|
67
|
+
* Return a new builder with the given instruction appended. Instructions
|
|
68
|
+
* render in insertion order. Accepts either raw text (auto-wrapped via
|
|
69
|
+
* `new Instruction`) or an existing `InstructionContract` instance for
|
|
70
|
+
* cross-prompt reuse.
|
|
71
|
+
*/
|
|
72
|
+
instruction(value: InstructionContract | string): SystemPromptContract;
|
|
73
|
+
/**
|
|
74
|
+
* Resolve every block against the placeholder map, join the results with
|
|
75
|
+
* blank-line separators (in insertion order), and trim. Returns an empty
|
|
76
|
+
* string when no blocks are present — callers treat that as "no system
|
|
77
|
+
* message".
|
|
78
|
+
*/
|
|
79
|
+
resolve(placeholders?: Placeholders): string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create a new immutable system-prompt builder.
|
|
83
|
+
*
|
|
84
|
+
* **Role.** Public factory for `SystemPrompt` — keeps user-facing code
|
|
85
|
+
* free of `new` and consistent with `ai.tool()`, `ai.agent()`,
|
|
86
|
+
* `ai.persona()`, `ai.instruction()`.
|
|
87
|
+
*
|
|
88
|
+
* Three input forms:
|
|
89
|
+
* - No argument → empty builder, chain `.persona()` / `.instruction()`
|
|
90
|
+
* - Single string → seeded with one instruction for quick one-shot prompts
|
|
91
|
+
* - Array of blocks → used verbatim, preserving insertion order
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* // Composed builder
|
|
95
|
+
* const prompt = systemPrompt()
|
|
96
|
+
* .persona("You are Alex, a senior TypeScript engineer.")
|
|
97
|
+
* .instruction("Always include working code examples.")
|
|
98
|
+
* .instruction("Respond in {{language|English}}.");
|
|
99
|
+
*
|
|
100
|
+
* prompt.resolve({ language: "Arabic" });
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* // One-shot seed
|
|
104
|
+
* const prompt = systemPrompt("Answer only with JSON matching the schema.");
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* // Array form — fully declarative
|
|
108
|
+
* const prompt = systemPrompt([
|
|
109
|
+
* ai.persona("You are Alex."),
|
|
110
|
+
* ai.instruction("Always cite sources."),
|
|
111
|
+
* ai.instruction("Respond in {{language|English}}."),
|
|
112
|
+
* ]);
|
|
113
|
+
*/
|
|
114
|
+
declare function systemPrompt(input?: string | ReadonlyArray<SystemPromptBlockContract>): SystemPrompt;
|
|
115
|
+
//#endregion
|
|
116
|
+
export { SystemPrompt, systemPrompt };
|
|
117
|
+
//# sourceMappingURL=system-prompt.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-prompt.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/system-prompt/system-prompt.ts"],"mappings":";;;;;;AA2DA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiD4C;AAyC5C;;;;;;;;;;;;;AAEe;;cA5FF,YAAA,YAAwB,oBAAA;EAAA,SAEjB,MAAA,WAAiB,yBAAA;cAAjB,MAAA,YAAiB,yBAAA;;;;;;;;;EAW5B,OAAA,CAAQ,KAAA,EAAO,eAAA,YAA2B,oBAAA;;;;;;;EAsB1C,WAAA,CACL,KAAA,EAAO,mBAAA,YACN,oBAAA;;;;;;;EAYI,OAAA,CAAQ,YAAA,GAAe,YAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyChB,YAAA,CACd,KAAA,YAAiB,aAAA,CAAc,yBAAA,IAC9B,YAAA"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Instruction } from "./instruction.mjs";
|
|
2
|
+
import { Persona } from "./persona.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../../@warlock.js/ai/src/system-prompt/system-prompt.ts
|
|
5
|
+
/**
|
|
6
|
+
* Concrete `SystemPromptContract` — an immutable layered prompt builder.
|
|
7
|
+
*
|
|
8
|
+
* **Role.** The top-level composer for a system prompt: it holds an ordered
|
|
9
|
+
* list of typed blocks (persona + instructions) and resolves the whole
|
|
10
|
+
* stack into one final string when the agent is about to call the model.
|
|
11
|
+
*
|
|
12
|
+
* **Responsibility.**
|
|
13
|
+
* - Owns: the ordered `blocks` list and the block-join rules (insertion
|
|
14
|
+
* order, blank-line separator, trim).
|
|
15
|
+
* - Does NOT own: how any individual block is rendered (delegated to each
|
|
16
|
+
* block's `resolve()`), the placeholder syntax (delegated to
|
|
17
|
+
* `renderPlaceholders`), or any knowledge of the agent, model, or
|
|
18
|
+
* session consuming the resolved text.
|
|
19
|
+
*
|
|
20
|
+
* Blocks are discriminated by a string `type` tag (`"persona"` /
|
|
21
|
+
* `"instruction"`) rather than `instanceof`, so user-supplied blocks that
|
|
22
|
+
* implement `SystemPromptBlockContract` interoperate seamlessly with blocks
|
|
23
|
+
* built via `ai.persona()` / `ai.instruction()` — even across duplicate
|
|
24
|
+
* package copies or bundler scope boundaries.
|
|
25
|
+
*
|
|
26
|
+
* The builder is **immutable** — every `.persona()` / `.instruction()`
|
|
27
|
+
* call returns a fresh `SystemPrompt` instance sharing nothing mutable
|
|
28
|
+
* with its parent. This makes forking a base prompt into specialized
|
|
29
|
+
* variants a safe, side-effect-free operation.
|
|
30
|
+
*
|
|
31
|
+
* Users construct via the `ai.systemPrompt()` factory — `new SystemPrompt()`
|
|
32
|
+
* is not the public API (see §4.2 of code-style.md). Modeled as a class so
|
|
33
|
+
* that methods live on the prototype (one copy shared across every forked
|
|
34
|
+
* instance) and downstream code can branch via `instanceof SystemPrompt`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // Chainable form
|
|
38
|
+
* const alex = ai.persona("You are Alex, a TypeScript expert.");
|
|
39
|
+
* const replyIn = ai.instruction("Respond in {{language|English}}.");
|
|
40
|
+
*
|
|
41
|
+
* const base = ai.systemPrompt().persona(alex).instruction(replyIn);
|
|
42
|
+
* const arabicVariant = base.instruction("Prefer Arabic comments.");
|
|
43
|
+
*
|
|
44
|
+
* base.resolve({ language: "English" });
|
|
45
|
+
* arabicVariant.resolve({ language: "Arabic" });
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // Array form — insertion order is preserved exactly
|
|
49
|
+
* const prompt = ai.systemPrompt([
|
|
50
|
+
* ai.persona("You are Alex, a TypeScript expert."),
|
|
51
|
+
* ai.instruction("Respond in {{language|English}}."),
|
|
52
|
+
* ]);
|
|
53
|
+
*/
|
|
54
|
+
var SystemPrompt = class SystemPrompt {
|
|
55
|
+
constructor(blocks = []) {
|
|
56
|
+
this.blocks = blocks;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Return a new builder with the persona block set. If a persona already
|
|
60
|
+
* exists it's replaced in place (preserving its position in `blocks`);
|
|
61
|
+
* otherwise the new persona is prepended so persona-first remains the
|
|
62
|
+
* default for chain-built prompts. Accepts either raw text (auto-wrapped
|
|
63
|
+
* via `new Persona`) or an existing `PersonaContract` instance for reuse
|
|
64
|
+
* across prompts.
|
|
65
|
+
*/
|
|
66
|
+
persona(value) {
|
|
67
|
+
const block = typeof value === "string" ? new Persona(value) : value;
|
|
68
|
+
const existingIndex = this.blocks.findIndex((candidate) => candidate.type === "persona");
|
|
69
|
+
if (existingIndex >= 0) {
|
|
70
|
+
const next = [...this.blocks];
|
|
71
|
+
next[existingIndex] = block;
|
|
72
|
+
return new SystemPrompt(next);
|
|
73
|
+
}
|
|
74
|
+
return new SystemPrompt([block, ...this.blocks]);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Return a new builder with the given instruction appended. Instructions
|
|
78
|
+
* render in insertion order. Accepts either raw text (auto-wrapped via
|
|
79
|
+
* `new Instruction`) or an existing `InstructionContract` instance for
|
|
80
|
+
* cross-prompt reuse.
|
|
81
|
+
*/
|
|
82
|
+
instruction(value) {
|
|
83
|
+
const block = typeof value === "string" ? new Instruction(value) : value;
|
|
84
|
+
return new SystemPrompt([...this.blocks, block]);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Resolve every block against the placeholder map, join the results with
|
|
88
|
+
* blank-line separators (in insertion order), and trim. Returns an empty
|
|
89
|
+
* string when no blocks are present — callers treat that as "no system
|
|
90
|
+
* message".
|
|
91
|
+
*/
|
|
92
|
+
resolve(placeholders) {
|
|
93
|
+
return this.blocks.map((block) => block.resolve(placeholders)).join("\n\n").trim();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Create a new immutable system-prompt builder.
|
|
98
|
+
*
|
|
99
|
+
* **Role.** Public factory for `SystemPrompt` — keeps user-facing code
|
|
100
|
+
* free of `new` and consistent with `ai.tool()`, `ai.agent()`,
|
|
101
|
+
* `ai.persona()`, `ai.instruction()`.
|
|
102
|
+
*
|
|
103
|
+
* Three input forms:
|
|
104
|
+
* - No argument → empty builder, chain `.persona()` / `.instruction()`
|
|
105
|
+
* - Single string → seeded with one instruction for quick one-shot prompts
|
|
106
|
+
* - Array of blocks → used verbatim, preserving insertion order
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* // Composed builder
|
|
110
|
+
* const prompt = systemPrompt()
|
|
111
|
+
* .persona("You are Alex, a senior TypeScript engineer.")
|
|
112
|
+
* .instruction("Always include working code examples.")
|
|
113
|
+
* .instruction("Respond in {{language|English}}.");
|
|
114
|
+
*
|
|
115
|
+
* prompt.resolve({ language: "Arabic" });
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* // One-shot seed
|
|
119
|
+
* const prompt = systemPrompt("Answer only with JSON matching the schema.");
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* // Array form — fully declarative
|
|
123
|
+
* const prompt = systemPrompt([
|
|
124
|
+
* ai.persona("You are Alex."),
|
|
125
|
+
* ai.instruction("Always cite sources."),
|
|
126
|
+
* ai.instruction("Respond in {{language|English}}."),
|
|
127
|
+
* ]);
|
|
128
|
+
*/
|
|
129
|
+
function systemPrompt(input) {
|
|
130
|
+
if (input === void 0) return new SystemPrompt();
|
|
131
|
+
if (typeof input === "string") return new SystemPrompt([new Instruction(input)]);
|
|
132
|
+
return new SystemPrompt([...input]);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//#endregion
|
|
136
|
+
export { SystemPrompt, systemPrompt };
|
|
137
|
+
//# sourceMappingURL=system-prompt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-prompt.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/system-prompt/system-prompt.ts"],"sourcesContent":["import type { Placeholders } from \"../contracts/placeholders.type\";\nimport type {\n InstructionContract,\n PersonaContract,\n SystemPromptBlockContract,\n SystemPromptContract,\n} from \"../contracts/system-prompt.contract\";\nimport { Instruction } from \"./instruction\";\nimport { Persona } from \"./persona\";\n\n/**\n * Concrete `SystemPromptContract` — an immutable layered prompt builder.\n *\n * **Role.** The top-level composer for a system prompt: it holds an ordered\n * list of typed blocks (persona + instructions) and resolves the whole\n * stack into one final string when the agent is about to call the model.\n *\n * **Responsibility.**\n * - Owns: the ordered `blocks` list and the block-join rules (insertion\n * order, blank-line separator, trim).\n * - Does NOT own: how any individual block is rendered (delegated to each\n * block's `resolve()`), the placeholder syntax (delegated to\n * `renderPlaceholders`), or any knowledge of the agent, model, or\n * session consuming the resolved text.\n *\n * Blocks are discriminated by a string `type` tag (`\"persona\"` /\n * `\"instruction\"`) rather than `instanceof`, so user-supplied blocks that\n * implement `SystemPromptBlockContract` interoperate seamlessly with blocks\n * built via `ai.persona()` / `ai.instruction()` — even across duplicate\n * package copies or bundler scope boundaries.\n *\n * The builder is **immutable** — every `.persona()` / `.instruction()`\n * call returns a fresh `SystemPrompt` instance sharing nothing mutable\n * with its parent. This makes forking a base prompt into specialized\n * variants a safe, side-effect-free operation.\n *\n * Users construct via the `ai.systemPrompt()` factory — `new SystemPrompt()`\n * is not the public API (see §4.2 of code-style.md). Modeled as a class so\n * that methods live on the prototype (one copy shared across every forked\n * instance) and downstream code can branch via `instanceof SystemPrompt`.\n *\n * @example\n * // Chainable form\n * const alex = ai.persona(\"You are Alex, a TypeScript expert.\");\n * const replyIn = ai.instruction(\"Respond in {{language|English}}.\");\n *\n * const base = ai.systemPrompt().persona(alex).instruction(replyIn);\n * const arabicVariant = base.instruction(\"Prefer Arabic comments.\");\n *\n * base.resolve({ language: \"English\" });\n * arabicVariant.resolve({ language: \"Arabic\" });\n *\n * @example\n * // Array form — insertion order is preserved exactly\n * const prompt = ai.systemPrompt([\n * ai.persona(\"You are Alex, a TypeScript expert.\"),\n * ai.instruction(\"Respond in {{language|English}}.\"),\n * ]);\n */\nexport class SystemPrompt implements SystemPromptContract {\n public constructor(\n public readonly blocks: readonly SystemPromptBlockContract[] = [],\n ) {}\n\n /**\n * Return a new builder with the persona block set. If a persona already\n * exists it's replaced in place (preserving its position in `blocks`);\n * otherwise the new persona is prepended so persona-first remains the\n * default for chain-built prompts. Accepts either raw text (auto-wrapped\n * via `new Persona`) or an existing `PersonaContract` instance for reuse\n * across prompts.\n */\n public persona(value: PersonaContract | string): SystemPromptContract {\n const block = typeof value === \"string\" ? new Persona(value) : value;\n const existingIndex = this.blocks.findIndex(\n candidate => candidate.type === \"persona\",\n );\n\n if (existingIndex >= 0) {\n const next = [...this.blocks];\n next[existingIndex] = block;\n\n return new SystemPrompt(next) as this;\n }\n\n return new SystemPrompt([block, ...this.blocks]);\n }\n\n /**\n * Return a new builder with the given instruction appended. Instructions\n * render in insertion order. Accepts either raw text (auto-wrapped via\n * `new Instruction`) or an existing `InstructionContract` instance for\n * cross-prompt reuse.\n */\n public instruction(\n value: InstructionContract | string,\n ): SystemPromptContract {\n const block = typeof value === \"string\" ? new Instruction(value) : value;\n\n return new SystemPrompt([...this.blocks, block]);\n }\n\n /**\n * Resolve every block against the placeholder map, join the results with\n * blank-line separators (in insertion order), and trim. Returns an empty\n * string when no blocks are present — callers treat that as \"no system\n * message\".\n */\n public resolve(placeholders?: Placeholders): string {\n return this.blocks\n .map(block => block.resolve(placeholders))\n .join(\"\\n\\n\")\n .trim();\n }\n}\n\n/**\n * Create a new immutable system-prompt builder.\n *\n * **Role.** Public factory for `SystemPrompt` — keeps user-facing code\n * free of `new` and consistent with `ai.tool()`, `ai.agent()`,\n * `ai.persona()`, `ai.instruction()`.\n *\n * Three input forms:\n * - No argument → empty builder, chain `.persona()` / `.instruction()`\n * - Single string → seeded with one instruction for quick one-shot prompts\n * - Array of blocks → used verbatim, preserving insertion order\n *\n * @example\n * // Composed builder\n * const prompt = systemPrompt()\n * .persona(\"You are Alex, a senior TypeScript engineer.\")\n * .instruction(\"Always include working code examples.\")\n * .instruction(\"Respond in {{language|English}}.\");\n *\n * prompt.resolve({ language: \"Arabic\" });\n *\n * @example\n * // One-shot seed\n * const prompt = systemPrompt(\"Answer only with JSON matching the schema.\");\n *\n * @example\n * // Array form — fully declarative\n * const prompt = systemPrompt([\n * ai.persona(\"You are Alex.\"),\n * ai.instruction(\"Always cite sources.\"),\n * ai.instruction(\"Respond in {{language|English}}.\"),\n * ]);\n */\nexport function systemPrompt(\n input?: string | ReadonlyArray<SystemPromptBlockContract>,\n): SystemPrompt {\n if (input === undefined) {\n return new SystemPrompt();\n }\n\n if (typeof input === \"string\") {\n return new SystemPrompt([new Instruction(input)]);\n }\n\n return new SystemPrompt([...input]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,IAAa,eAAb,MAAa,aAA6C;CACxD,AAAO,YACL,AAAgB,SAA+C,CAAC,GAChE;EADgB;CACf;;;;;;;;;CAUH,AAAO,QAAQ,OAAuD;EACpE,MAAM,QAAQ,OAAO,UAAU,WAAW,IAAI,QAAQ,KAAK,IAAI;EAC/D,MAAM,gBAAgB,KAAK,OAAO,WAChC,cAAa,UAAU,SAAS,SAClC;EAEA,IAAI,iBAAiB,GAAG;GACtB,MAAM,OAAO,CAAC,GAAG,KAAK,MAAM;GAC5B,KAAK,iBAAiB;GAEtB,OAAO,IAAI,aAAa,IAAI;EAC9B;EAEA,OAAO,IAAI,aAAa,CAAC,OAAO,GAAG,KAAK,MAAM,CAAC;CACjD;;;;;;;CAQA,AAAO,YACL,OACsB;EACtB,MAAM,QAAQ,OAAO,UAAU,WAAW,IAAI,YAAY,KAAK,IAAI;EAEnE,OAAO,IAAI,aAAa,CAAC,GAAG,KAAK,QAAQ,KAAK,CAAC;CACjD;;;;;;;CAQA,AAAO,QAAQ,cAAqC;EAClD,OAAO,KAAK,OACT,KAAI,UAAS,MAAM,QAAQ,YAAY,CAAC,EACxC,KAAK,MAAM,EACX,KAAK;CACV;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,aACd,OACc;CACd,IAAI,UAAU,QACZ,OAAO,IAAI,aAAa;CAG1B,IAAI,OAAO,UAAU,UACnB,OAAO,IAAI,aAAa,CAAC,IAAI,YAAY,KAAK,CAAC,CAAC;CAGlD,OAAO,IAAI,aAAa,CAAC,GAAG,KAAK,CAAC;AACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { ToolContract, ToolInvokeResult, tool } from "./tool.mjs";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AIError } from "../errors/ai-error.mjs";
|
|
2
|
+
import { Usage } from "../contracts/result/usage.type.mjs";
|
|
3
|
+
import { BaseReport } from "../contracts/result/base-report.type.mjs";
|
|
4
|
+
import { ToolConfig, ToolContext } from "../contracts/tool.contract.mjs";
|
|
5
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
+
|
|
7
|
+
//#region ../../@warlock.js/ai/src/tool/tool.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Result returned by `ToolContract.invoke()`.
|
|
10
|
+
*
|
|
11
|
+
* **Canonical destructure:** `const { data, usage, report, error }` —
|
|
12
|
+
* matches every other executable (`AgentResult`, `WorkflowResult`,
|
|
13
|
+
* `SupervisorResult`) so parent agents can treat every tool dispatch
|
|
14
|
+
* uniformly.
|
|
15
|
+
*
|
|
16
|
+
* **Shape.** `data` / `error` carry the outcome; `usage` and `report`
|
|
17
|
+
* are always present. For leaf tools, `usage` is zero and `report`
|
|
18
|
+
* is a framework-synthesized {@link BaseReport} (`type: "tool"`,
|
|
19
|
+
* `children: []`, real timing) so parents never have to nil-check.
|
|
20
|
+
* For composites wrapped via `asTool()`, `usage` and `report` mirror
|
|
21
|
+
* the inner primitive's — the nested tree lives in `report.children`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const result = await myTool.invoke({ city: "Cairo" });
|
|
25
|
+
* if (result.error) console.error(result.error.message);
|
|
26
|
+
* else console.log(result.data, result.report.duration);
|
|
27
|
+
*/
|
|
28
|
+
type ToolInvokeResult<TOutput> = {
|
|
29
|
+
/** Successfully-returned output. Undefined if execution or validation failed. */data?: TOutput; /** Typed AI error produced by validation or execute(), if any. */
|
|
30
|
+
error?: AIError; /** Rolled-up usage (zero for leaf tools, populated for composites). */
|
|
31
|
+
usage: Usage; /** Recursive execution report — `report.children` carries nested executables. */
|
|
32
|
+
report: BaseReport;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* A `ToolConfig` augmented with a safe `invoke()` entry point for the agent runtime.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const wrapped: ToolContract<{ city: string }, { temp: number }> = tool(contract);
|
|
39
|
+
* const result = await wrapped.invoke({ city: "Cairo" });
|
|
40
|
+
*/
|
|
41
|
+
interface ToolContract<TInput = unknown, TOutput = unknown> extends ToolConfig<TInput, TOutput> {
|
|
42
|
+
/**
|
|
43
|
+
* Agent-runtime entry point. Validates raw input against the tool's schema,
|
|
44
|
+
* calls execute(), catches errors, and reports duration.
|
|
45
|
+
* Never throws — errors surface in the returned `error` field as
|
|
46
|
+
* typed `AIError` subclasses.
|
|
47
|
+
*
|
|
48
|
+
* The optional second argument is a `ToolContext` (Phase 5 /
|
|
49
|
+
* decisions §35) — when supplied, threaded into `execute(input, ctx)`
|
|
50
|
+
* so tools can write system-only side data into `ctx.artifacts`.
|
|
51
|
+
* Standalone callers may omit it; the framework supplies a
|
|
52
|
+
* degraded `{ artifacts: {} }` so single-arg legacy handlers keep
|
|
53
|
+
* working unchanged.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const result = await myTool.invoke(rawLLMArgs);
|
|
57
|
+
* if (result.error) handleError(result.error);
|
|
58
|
+
*/
|
|
59
|
+
invoke(rawInput: unknown, ctx?: ToolContext): Promise<ToolInvokeResult<TOutput>>;
|
|
60
|
+
}
|
|
61
|
+
declare function tool<TInput, TOutput>(contract: ToolConfig<TInput, TOutput>): ToolContract<TInput, TOutput>;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { ToolContract, ToolInvokeResult, tool };
|
|
64
|
+
//# sourceMappingURL=tool.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/tool/tool.ts"],"mappings":";;;;;;;;;;AAwCA;;;;;;;;;;;;;;;;;KAAY,gBAAA;EAQQ,iFANlB,IAAA,GAAO,OAAA,EAgBQ;EAdf,KAAA,GAAQ,OAAA,EAcmB;EAZ3B,KAAA,EAAO,KAAA,EAcP;EAZA,MAAA,EAAQ,UAAA;AAAA;;;;;;;;UAUO,YAAA,8CAA0D,UAAA,CACzE,MAAA,EACA,OAAA;EADA;;;;;;;;;;AAoB8E;AAuJhF;;;;;;EAvJE,MAAA,CAAO,QAAA,WAAmB,GAAA,GAAM,WAAA,GAAc,OAAA,CAAQ,gBAAA,CAAiB,OAAA;AAAA;AAAA,iBAuJzD,IAAA,iBAAA,CACd,QAAA,EAAU,UAAA,CAAW,MAAA,EAAQ,OAAA,IAC5B,YAAA,CAAa,MAAA,EAAQ,OAAA"}
|