@earendil-works/pi-coding-agent 0.85.0 → 0.85.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/CHANGELOG.md +18 -0
- package/README.md +0 -2
- package/dist/bun/cli.d.ts +3 -1
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +3 -12
- package/dist/bun/cli.js.map +1 -1
- package/dist/bun/sandbox-env-setup.d.ts +2 -0
- package/dist/bun/sandbox-env-setup.d.ts.map +1 -0
- package/dist/bun/sandbox-env-setup.js +4 -0
- package/dist/bun/sandbox-env-setup.js.map +1 -0
- package/dist/bundle/chunks/{anthropic-messages-QAQLEQIY.js → anthropic-messages-VWZZOSJQ.js} +1 -1
- package/dist/bundle/chunks/{azure-openai-responses-Q7MJBRE6.js → azure-openai-responses-BJLAM6CD.js} +1 -1
- package/dist/bundle/chunks/{chunk-R7UUJ4C2.js → chunk-CLNPYIDP.js} +1 -1
- package/dist/bundle/chunks/chunk-JVUZSMYM.js +1547 -0
- package/dist/bundle/chunks/{chunk-2KVJKXS2.js → chunk-U6ZMQKGD.js} +1 -1
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/{google-generative-ai-BSMTYDAM.js → google-generative-ai-Q2K7FBDI.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-5C3HASOJ.js → google-vertex-7UJBF4S7.js} +1 -1
- package/dist/bundle/chunks/{node-EM5FIVUN.js → node-KG362ECQ.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-YJOO52RW.js → openai-codex-responses-R6VYZTVY.js} +1 -1
- package/dist/bundle/chunks/{openai-completions-QOT3QX7D.js → openai-completions-EKZT2IH2.js} +1 -1
- package/dist/bundle/chunks/openai-responses-TFDINO6W.js +2 -0
- package/dist/bundle/chunks/{pi-messages-EGZIFQGG.js → pi-messages-PML4SPVJ.js} +1 -1
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +0 -2
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/setup.d.ts +2 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +12 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -25
- package/dist/cli.js.map +1 -1
- package/dist/core/keybindings.d.ts +5 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +4 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +0 -122
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +5 -5
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +8 -8
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +4 -4
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/docs/containerization.md +45 -0
- package/docs/development.md +19 -0
- package/docs/environment-variables.md +2 -2
- package/docs/keybindings.md +2 -1
- package/docs/models.md +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +20 -46
- package/package.json +13 -12
- package/dist/bundle/chunks/chunk-EQ6DR6XK.js +0 -5
- package/dist/bundle/chunks/chunk-LZKJTKCT.js +0 -2
- package/dist/bundle/chunks/chunk-WBE4J4AU.js +0 -9
- package/dist/bundle/chunks/chunk-WZB2R5YO.js +0 -1558
- package/dist/bundle/chunks/openai-responses-U7LNPQN4.js +0 -2
- package/dist/bundle/client.js +0 -2
- package/dist/bundle/coordinator.js +0 -3
- package/dist/cli/experimental/cli.d.ts +0 -10
- package/dist/cli/experimental/cli.d.ts.map +0 -1
- package/dist/cli/experimental/cli.js +0 -9
- package/dist/cli/experimental/cli.js.map +0 -1
- package/dist/cli/experimental/command-options.d.ts +0 -28
- package/dist/cli/experimental/command-options.d.ts.map +0 -1
- package/dist/cli/experimental/command-options.js +0 -84
- package/dist/cli/experimental/command-options.js.map +0 -1
- package/dist/cli/experimental/command.d.ts +0 -70
- package/dist/cli/experimental/command.d.ts.map +0 -1
- package/dist/cli/experimental/command.js +0 -144
- package/dist/cli/experimental/command.js.map +0 -1
- package/dist/cli/experimental/commands/client.d.ts +0 -19
- package/dist/cli/experimental/commands/client.d.ts.map +0 -1
- package/dist/cli/experimental/commands/client.js +0 -63
- package/dist/cli/experimental/commands/client.js.map +0 -1
- package/dist/cli/experimental/commands/server.d.ts +0 -17
- package/dist/cli/experimental/commands/server.d.ts.map +0 -1
- package/dist/cli/experimental/commands/server.js +0 -44
- package/dist/cli/experimental/commands/server.js.map +0 -1
- package/dist/client/index.d.ts +0 -2
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js +0 -2
- package/dist/client/index.js.map +0 -1
- package/dist/experimental/client-runtime.d.ts +0 -43
- package/dist/experimental/client-runtime.d.ts.map +0 -1
- package/dist/experimental/client-runtime.js +0 -183
- package/dist/experimental/client-runtime.js.map +0 -1
- package/dist/experimental/client-tui-chat.d.ts +0 -14
- package/dist/experimental/client-tui-chat.d.ts.map +0 -1
- package/dist/experimental/client-tui-chat.js +0 -171
- package/dist/experimental/client-tui-chat.js.map +0 -1
- package/dist/experimental/client-tui.d.ts +0 -37
- package/dist/experimental/client-tui.d.ts.map +0 -1
- package/dist/experimental/client-tui.js +0 -702
- package/dist/experimental/client-tui.js.map +0 -1
- package/dist/experimental/client.d.ts +0 -25
- package/dist/experimental/client.d.ts.map +0 -1
- package/dist/experimental/client.js +0 -99
- package/dist/experimental/client.js.map +0 -1
- package/dist/experimental/coordinator-entry.d.ts +0 -3
- package/dist/experimental/coordinator-entry.d.ts.map +0 -1
- package/dist/experimental/coordinator-entry.js +0 -11
- package/dist/experimental/coordinator-entry.js.map +0 -1
- package/dist/experimental/coordinator.d.ts +0 -38
- package/dist/experimental/coordinator.d.ts.map +0 -1
- package/dist/experimental/coordinator.js +0 -570
- package/dist/experimental/coordinator.js.map +0 -1
- package/dist/experimental/mini/main.d.ts +0 -7
- package/dist/experimental/mini/main.d.ts.map +0 -1
- package/dist/experimental/mini/main.js +0 -21
- package/dist/experimental/mini/main.js.map +0 -1
- package/dist/experimental/mini/server/entry.d.ts +0 -3
- package/dist/experimental/mini/server/entry.d.ts.map +0 -1
- package/dist/experimental/mini/server/entry.js +0 -11
- package/dist/experimental/mini/server/entry.js.map +0 -1
- package/dist/experimental/mini/server/run.d.ts +0 -13
- package/dist/experimental/mini/server/run.d.ts.map +0 -1
- package/dist/experimental/mini/server/run.js +0 -150
- package/dist/experimental/mini/server/run.js.map +0 -1
- package/dist/experimental/mini/shared/protocol.d.ts +0 -127
- package/dist/experimental/mini/shared/protocol.d.ts.map +0 -1
- package/dist/experimental/mini/shared/protocol.js +0 -13
- package/dist/experimental/mini/shared/protocol.js.map +0 -1
- package/dist/experimental/mini/shared/rpc.d.ts +0 -49
- package/dist/experimental/mini/shared/rpc.d.ts.map +0 -1
- package/dist/experimental/mini/shared/rpc.js +0 -171
- package/dist/experimental/mini/shared/rpc.js.map +0 -1
- package/dist/experimental/mini/shared/transport.d.ts +0 -35
- package/dist/experimental/mini/shared/transport.d.ts.map +0 -1
- package/dist/experimental/mini/shared/transport.js +0 -94
- package/dist/experimental/mini/shared/transport.js.map +0 -1
- package/dist/experimental/mini/tui/run.d.ts +0 -9
- package/dist/experimental/mini/tui/run.d.ts.map +0 -1
- package/dist/experimental/mini/tui/run.js +0 -62
- package/dist/experimental/mini/tui/run.js.map +0 -1
- package/dist/experimental/mini/tui/session.d.ts +0 -26
- package/dist/experimental/mini/tui/session.d.ts.map +0 -1
- package/dist/experimental/mini/tui/session.js +0 -94
- package/dist/experimental/mini/tui/session.js.map +0 -1
- package/dist/experimental/mini/tui/view.d.ts +0 -10
- package/dist/experimental/mini/tui/view.d.ts.map +0 -1
- package/dist/experimental/mini/tui/view.js +0 -459
- package/dist/experimental/mini/tui/view.js.map +0 -1
- package/dist/experimental/mini/worker/entry.d.ts +0 -3
- package/dist/experimental/mini/worker/entry.d.ts.map +0 -1
- package/dist/experimental/mini/worker/entry.js +0 -10
- package/dist/experimental/mini/worker/entry.js.map +0 -1
- package/dist/experimental/mini/worker/lane-service.d.ts +0 -44
- package/dist/experimental/mini/worker/lane-service.d.ts.map +0 -1
- package/dist/experimental/mini/worker/lane-service.js +0 -97
- package/dist/experimental/mini/worker/lane-service.js.map +0 -1
- package/dist/experimental/mini/worker/models-service.d.ts +0 -19
- package/dist/experimental/mini/worker/models-service.d.ts.map +0 -1
- package/dist/experimental/mini/worker/models-service.js +0 -136
- package/dist/experimental/mini/worker/models-service.js.map +0 -1
- package/dist/experimental/mini/worker/run.d.ts +0 -14
- package/dist/experimental/mini/worker/run.d.ts.map +0 -1
- package/dist/experimental/mini/worker/run.js +0 -88
- package/dist/experimental/mini/worker/run.js.map +0 -1
- package/dist/experimental/plugin.d.ts +0 -4
- package/dist/experimental/plugin.d.ts.map +0 -1
- package/dist/experimental/plugin.js +0 -4
- package/dist/experimental/plugin.js.map +0 -1
- package/dist/experimental/plugins/bundled.d.ts +0 -7
- package/dist/experimental/plugins/bundled.d.ts.map +0 -1
- package/dist/experimental/plugins/bundled.js +0 -48
- package/dist/experimental/plugins/bundled.js.map +0 -1
- package/dist/experimental/plugins/package.d.ts +0 -18
- package/dist/experimental/plugins/package.d.ts.map +0 -1
- package/dist/experimental/plugins/package.js +0 -113
- package/dist/experimental/plugins/package.js.map +0 -1
- package/dist/experimental/process.d.ts +0 -20
- package/dist/experimental/process.d.ts.map +0 -1
- package/dist/experimental/process.js +0 -85
- package/dist/experimental/process.js.map +0 -1
- package/dist/experimental/radius-auth.d.ts +0 -17
- package/dist/experimental/radius-auth.d.ts.map +0 -1
- package/dist/experimental/radius-auth.js +0 -52
- package/dist/experimental/radius-auth.js.map +0 -1
- package/dist/experimental/radius-relay.d.ts +0 -90
- package/dist/experimental/radius-relay.d.ts.map +0 -1
- package/dist/experimental/radius-relay.js +0 -582
- package/dist/experimental/radius-relay.js.map +0 -1
- package/dist/experimental/server.d.ts +0 -75
- package/dist/experimental/server.d.ts.map +0 -1
- package/dist/experimental/server.js +0 -682
- package/dist/experimental/server.js.map +0 -1
- package/dist/experimental/services/agent-controller-provider.d.ts +0 -4
- package/dist/experimental/services/agent-controller-provider.d.ts.map +0 -1
- package/dist/experimental/services/agent-controller-provider.js +0 -84
- package/dist/experimental/services/agent-controller-provider.js.map +0 -1
- package/dist/experimental/services/agent-controller.d.ts +0 -57
- package/dist/experimental/services/agent-controller.d.ts.map +0 -1
- package/dist/experimental/services/agent-controller.js +0 -3
- package/dist/experimental/services/agent-controller.js.map +0 -1
- package/dist/experimental/services/connection.d.ts +0 -40
- package/dist/experimental/services/connection.d.ts.map +0 -1
- package/dist/experimental/services/connection.js +0 -300
- package/dist/experimental/services/connection.js.map +0 -1
- package/dist/experimental/services/models-provider.d.ts +0 -16
- package/dist/experimental/services/models-provider.d.ts.map +0 -1
- package/dist/experimental/services/models-provider.js +0 -116
- package/dist/experimental/services/models-provider.js.map +0 -1
- package/dist/experimental/services/models.d.ts +0 -36
- package/dist/experimental/services/models.d.ts.map +0 -1
- package/dist/experimental/services/models.js +0 -3
- package/dist/experimental/services/models.js.map +0 -1
- package/dist/experimental/services/plugins.d.ts +0 -16
- package/dist/experimental/services/plugins.d.ts.map +0 -1
- package/dist/experimental/services/plugins.js +0 -4
- package/dist/experimental/services/plugins.js.map +0 -1
- package/dist/experimental/services/presentation-ui.d.ts +0 -13
- package/dist/experimental/services/presentation-ui.d.ts.map +0 -1
- package/dist/experimental/services/presentation-ui.js +0 -3
- package/dist/experimental/services/presentation-ui.js.map +0 -1
- package/dist/experimental/services/server.d.ts +0 -19
- package/dist/experimental/services/server.d.ts.map +0 -1
- package/dist/experimental/services/server.js +0 -104
- package/dist/experimental/services/server.js.map +0 -1
- package/dist/experimental/services/sessions.d.ts +0 -28
- package/dist/experimental/services/sessions.d.ts.map +0 -1
- package/dist/experimental/services/sessions.js +0 -4
- package/dist/experimental/services/sessions.js.map +0 -1
- package/dist/experimental/services/slash-commands-provider.d.ts +0 -14
- package/dist/experimental/services/slash-commands-provider.d.ts.map +0 -1
- package/dist/experimental/services/slash-commands-provider.js +0 -200
- package/dist/experimental/services/slash-commands-provider.js.map +0 -1
- package/dist/experimental/services/slash-commands.d.ts +0 -24
- package/dist/experimental/services/slash-commands.d.ts.map +0 -1
- package/dist/experimental/services/slash-commands.js +0 -3
- package/dist/experimental/services/slash-commands.js.map +0 -1
- package/dist/experimental/services/transcript-provider.d.ts +0 -12
- package/dist/experimental/services/transcript-provider.d.ts.map +0 -1
- package/dist/experimental/services/transcript-provider.js +0 -109
- package/dist/experimental/services/transcript-provider.js.map +0 -1
- package/dist/experimental/services/transcript.d.ts +0 -13
- package/dist/experimental/services/transcript.d.ts.map +0 -1
- package/dist/experimental/services/transcript.js +0 -3
- package/dist/experimental/services/transcript.js.map +0 -1
- package/dist/experimental/services/worker.d.ts +0 -28
- package/dist/experimental/services/worker.d.ts.map +0 -1
- package/dist/experimental/services/worker.js +0 -107
- package/dist/experimental/services/worker.js.map +0 -1
- package/dist/experimental/session-worker-manager.d.ts +0 -24
- package/dist/experimental/session-worker-manager.d.ts.map +0 -1
- package/dist/experimental/session-worker-manager.js +0 -691
- package/dist/experimental/session-worker-manager.js.map +0 -1
- package/dist/experimental/session-worker.d.ts +0 -188
- package/dist/experimental/session-worker.d.ts.map +0 -1
- package/dist/experimental/session-worker.js +0 -785
- package/dist/experimental/session-worker.js.map +0 -1
- package/dist/experimental/source-resolver.d.ts +0 -2
- package/dist/experimental/source-resolver.d.ts.map +0 -1
- package/dist/experimental/source-resolver.js +0 -71
- package/dist/experimental/source-resolver.js.map +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
|
|
2
|
-
import{splitDeferredTools}from"./chunk-GMWCTUPB.js";import{convertResponsesMessages,convertResponsesTools,processResponsesStream}from"./chunk-OUXLLA64.js";import{buildCopilotDynamicHeaders,hasCopilotVisionInput}from"./chunk-PGXDEOVV.js";import{clampOpenAIPromptCacheKey}from"./chunk-PRRNXB7S.js";import"./chunk-PJACZCIR.js";import{OpenAI}from"./chunk-NUHFSC37.js";import{formatProviderError,normalizeProviderError}from"./chunk-TEPMHNKQ.js";import{buildBaseOptions,createGrammarToolInputProperties,getPiUserAgent}from"./chunk-AXIIZGTV.js";import{retryProviderRequest}from"./chunk-XNGRGP62.js";import"./chunk-L2ZPNLYD.js";import{headersToRecord}from"./chunk-6R7UI4IY.js";import"./chunk-TRDNDS6A.js";import{getProviderEnvValue}from"./chunk-DRQDKNXA.js";import{clampThinkingLevel}from"./chunk-IDDQWTHI.js";import{AssistantMessageEventStream}from"./chunk-UAQELI3K.js";import"./chunk-4L3WN2XY.js";var OPENAI_TOOL_CALL_PROVIDERS=new Set(["openai","openai-codex","opencode"]),OPENAI_RESPONSES_MIN_OUTPUT_TOKENS=16;function hasHeader(headers,name){if(!headers)return!1;let expected=name.toLowerCase();for(let[key,value]of Object.entries(headers))if(key.toLowerCase()===expected&&value!==null&&value.trim().length>0)return!0;return!1}function getClientApiKey(provider,apiKey,headers){if(apiKey)return apiKey;if(hasHeader(headers,"authorization")||hasHeader(headers,"cf-aig-authorization"))return"unused";throw new Error(`No API key for provider: ${provider}`)}function detectSessionAffinityFormat(model){return model.provider==="openrouter"||model.baseUrl.includes("openrouter.ai")?"openrouter":"openai"}function resolveCacheRetention(cacheRetention,env){return cacheRetention||(getProviderEnvValue("PI_CACHE_RETENTION",env)==="long"?"long":"short")}function getCompat(model){return{supportsDeveloperRole:model.compat?.supportsDeveloperRole??!0,sessionAffinityFormat:model.compat?.sessionAffinityFormat??detectSessionAffinityFormat(model),supportsLongCacheRetention:model.compat?.supportsLongCacheRetention??!0,supportsStrictMode:model.compat?.supportsStrictMode??!1,supportsOpenAIGrammarTools:model.compat?.supportsOpenAIGrammarTools??!1,supportsAdditionalTools:model.compat?.supportsAdditionalTools??!1,supportsToolSearch:model.compat?.supportsToolSearch??!1,supportsExplicitPromptCacheMode:model.compat?.supportsExplicitPromptCacheMode??!1,supportsMaxOutputTokens:model.compat?.supportsMaxOutputTokens??!0}}function getPromptCacheRetention(compat,cacheRetention){return cacheRetention==="long"&&compat.supportsLongCacheRetention?"24h":void 0}function formatOpenAIResponsesError(error){return formatProviderError(normalizeProviderError(error),"OpenAI API error")}var stream=(model,context,options)=>{let stream2=new AssistantMessageEventStream;return(async()=>{let output={role:"assistant",content:[],api:model.api,provider:model.provider,model:model.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"pending",timestamp:Date.now()};try{let apiKey=getClientApiKey(model.provider,options?.apiKey,options?.headers),cacheSessionId=resolveCacheRetention(options?.cacheRetention,options?.env)==="none"?void 0:options?.sessionId,compat=getCompat(model),grammarToolInputProperties=createGrammarToolInputProperties(context.tools,compat.supportsOpenAIGrammarTools),client=createClient(model,context,apiKey,options?.headers,options?.fetch,cacheSessionId),params=buildParams(model,context,options,compat,grammarToolInputProperties),nextParams=await options?.onPayload?.(params,model);nextParams!==void 0&&(params=nextParams);let requestOptions={...options?.signal?{signal:options.signal}:{},...options?.timeoutMs!==void 0?{timeout:options.timeoutMs}:{},maxRetries:0},{data:openaiStream,response}=await retryProviderRequest(()=>client.responses.create(params,requestOptions).withResponse(),{maxRetries:options?.maxRetries,maxRetryDelayMs:options?.maxRetryDelayMs,signal:options?.signal});if(await options?.onResponse?.({status:response.status,headers:headersToRecord(response.headers)},model),stream2.push({type:"start",partial:output}),await processResponsesStream(openaiStream,output,stream2,model,{serviceTier:options?.serviceTier,grammarToolInputProperties,applyServiceTierPricing:(usage,serviceTier)=>applyServiceTierPricing(usage,serviceTier,model)}),options?.signal?.aborted)throw new Error("Request was aborted");if(output.stopReason==="pending")throw new Error("OpenAI Responses stream ended without a stop reason");if(output.stopReason==="aborted"||output.stopReason==="error")throw new Error(output.errorMessage||"An unknown error occurred");stream2.push({type:"done",reason:output.stopReason,message:output}),stream2.end()}catch(error){for(let block of output.content)delete block.index,delete block.partialJson,delete block.customInput;output.stopReason=options?.signal?.aborted?"aborted":"error",output.errorMessage=formatOpenAIResponsesError(error),stream2.push({type:"error",reason:output.stopReason,error:output}),stream2.end()}})(),stream2},streamSimple=(model,context,options)=>{getClientApiKey(model.provider,options?.apiKey,options?.headers);let base={...buildBaseOptions(model,context,options,options?.apiKey),toolChoice:options?.toolChoice},clampedReasoning=options?.reasoning?clampThinkingLevel(model,options.reasoning):void 0;return stream(model,context,{...base,reasoningEffort:clampedReasoning==="off"?void 0:clampedReasoning})};function createClient(model,context,apiKey,optionsHeaders,fetch,sessionId){let compat=getCompat(model),headers={"User-Agent":getPiUserAgent(),...model.headers};if(model.provider==="github-copilot"){let hasImages=hasCopilotVisionInput(context.messages),copilotHeaders=buildCopilotDynamicHeaders({messages:context.messages,hasImages});Object.assign(headers,copilotHeaders)}return sessionId&&(compat.sessionAffinityFormat==="openrouter"?headers["x-session-id"]=sessionId:(compat.sessionAffinityFormat==="openai"&&(headers.session_id=sessionId),headers["x-client-request-id"]=sessionId)),optionsHeaders&&Object.assign(headers,optionsHeaders),new OpenAI({apiKey,baseURL:model.baseUrl,dangerouslyAllowBrowser:!0,fetch,defaultHeaders:headers})}function buildParams(model,context,options,compat=getCompat(model),grammarToolInputProperties=createGrammarToolInputProperties(context.tools,compat.supportsOpenAIGrammarTools)){let deferredToolsMode=compat.supportsAdditionalTools?"additional-tools":compat.supportsToolSearch?"tool-search":void 0,toolPlacement=splitDeferredTools(context,deferredToolsMode!==void 0),messages=convertResponsesMessages(model,context,OPENAI_TOOL_CALL_PROVIDERS,{grammarToolInputProperties,deferredTools:toolPlacement.deferred,deferredToolsMode,toolOptions:{supportsStrictMode:compat.supportsStrictMode,supportsOpenAIGrammarTools:compat.supportsOpenAIGrammarTools}}),cacheRetention=resolveCacheRetention(options?.cacheRetention,options?.env),disableImplicitPromptCache=cacheRetention==="none"&&compat.supportsExplicitPromptCacheMode,params={model:model.id,input:messages,stream:!0,prompt_cache_key:cacheRetention==="none"?void 0:clampOpenAIPromptCacheKey(options?.sessionId),prompt_cache_retention:getPromptCacheRetention(compat,cacheRetention),prompt_cache_options:disableImplicitPromptCache?{mode:"explicit"}:void 0,store:!1};if(options?.maxTokens&&compat.supportsMaxOutputTokens&&(params.max_output_tokens=Math.max(options.maxTokens,OPENAI_RESPONSES_MIN_OUTPUT_TOKENS)),options?.temperature!==void 0&&(params.temperature=options?.temperature),options?.serviceTier!==void 0&&(params.service_tier=options.serviceTier),toolPlacement.immediate.length>0&&(params.tools=convertResponsesTools(toolPlacement.immediate,{supportsStrictMode:compat.supportsStrictMode,supportsOpenAIGrammarTools:compat.supportsOpenAIGrammarTools})),options?.toolChoice!==void 0&&(params.tool_choice=options.toolChoice),model.reasoning){if(options?.reasoningEffort||options?.reasoningSummary){let effort=options?.reasoningEffort?model.thinkingLevelMap?.[options.reasoningEffort]??options.reasoningEffort:"medium";params.reasoning={effort,summary:options?.reasoningSummary||"auto"},params.include=["reasoning.encrypted_content"]}else model.provider!=="github-copilot"&&model.thinkingLevelMap?.off!==null&&(params.reasoning={effort:model.thinkingLevelMap?.off??"none"});model.provider==="xai"&&(params.include=["reasoning.encrypted_content"])}return options?.samplingParams&&Object.assign(params,options.samplingParams),params}function getServiceTierCostMultiplier(model,serviceTier){switch(serviceTier){case"flex":return .5;case"priority":return model.id==="gpt-5.5"?2.5:2;default:return 1}}function applyServiceTierPricing(usage,serviceTier,model){let multiplier=getServiceTierCostMultiplier(model,serviceTier);multiplier!==1&&(usage.cost.input*=multiplier,usage.cost.output*=multiplier,usage.cost.cacheRead*=multiplier,usage.cost.cacheWrite*=multiplier,usage.cost.total=usage.cost.input+usage.cost.output+usage.cost.cacheRead+usage.cost.cacheWrite)}export{stream,streamSimple};
|
package/dist/bundle/client.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
|
|
2
|
-
import{Client,ClientDisposedError,DisconnectedError,ServerError,createClientServiceTransport}from"./chunks/chunk-LZKJTKCT.js";import"./chunks/chunk-WBE4J4AU.js";import"./chunks/chunk-4L3WN2XY.js";export{Client,ClientDisposedError,DisconnectedError,ServerError,createClientServiceTransport};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
|
|
3
|
-
import{consumeInternalProcessRole,runCoordinatorProcess}from"./chunks/chunk-EQ6DR6XK.js";import"./chunks/chunk-WBE4J4AU.js";import"./chunks/chunk-4L3WN2XY.js";var role=consumeInternalProcessRole();if(role!=="coordinator")throw new Error("Coordinator entrypoint requires an internal coordinator invocation");runCoordinatorProcess(process.argv.slice(2)).catch(error=>{console.error(error),process.exit(1)});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Command } from "./command.ts";
|
|
2
|
-
import { type ClientCommandContext } from "./commands/client.ts";
|
|
3
|
-
import { type ServerCommandContext } from "./commands/server.ts";
|
|
4
|
-
interface ExperimentalCommandGroup {
|
|
5
|
-
readonly command: "experimental";
|
|
6
|
-
}
|
|
7
|
-
export type CliContext = ServerCommandContext & ClientCommandContext;
|
|
8
|
-
export declare const cli: Command<ExperimentalCommandGroup, ServerCommandContext & ClientCommandContext, import("./commands/client.ts").ClientCommand | ExperimentalCommandGroup | import("./commands/server.ts").ServerCommand>;
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/cli/experimental/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,KAAK,oBAAoB,EAAiB,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,KAAK,oBAAoB,EAAiB,MAAM,sBAAsB,CAAC;AAEhF,UAAU,wBAAwB;IACjC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,MAAM,UAAU,GAAG,oBAAoB,GAAG,oBAAoB,CAAC;AAOrE,eAAO,MAAM,GAAG,wMAAoE,CAAC","sourcesContent":["import { Command } from \"./command.ts\";\nimport { type ClientCommandContext, clientCommand } from \"./commands/client.ts\";\nimport { type ServerCommandContext, serverCommand } from \"./commands/server.ts\";\n\ninterface ExperimentalCommandGroup {\n\treadonly command: \"experimental\";\n}\n\nexport type CliContext = ServerCommandContext & ClientCommandContext;\n\nconst experimentalCommand = new Command<ExperimentalCommandGroup, CliContext>(\"experimental\").build(() => ({\n\tok: false,\n\terrors: [\"Expected experimental command: server or client\"],\n}));\n\nexport const cli = experimentalCommand.command(serverCommand).command(clientCommand);\n"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Command } from "./command.js";
|
|
2
|
-
import { clientCommand } from "./commands/client.js";
|
|
3
|
-
import { serverCommand } from "./commands/server.js";
|
|
4
|
-
const experimentalCommand = new Command("experimental").build(() => ({
|
|
5
|
-
ok: false,
|
|
6
|
-
errors: ["Expected experimental command: server or client"],
|
|
7
|
-
}));
|
|
8
|
-
export const cli = experimentalCommand.command(serverCommand).command(clientCommand);
|
|
9
|
-
//# sourceMappingURL=cli.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/cli/experimental/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAA6B,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAA6B,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAQhF,MAAM,mBAAmB,GAAG,IAAI,OAAO,CAAuC,cAAc,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;IAC1G,EAAE,EAAE,KAAK;IACT,MAAM,EAAE,CAAC,iDAAiD,CAAC;CAC3D,CAAC,CAAC,CAAC;AAEJ,MAAM,CAAC,MAAM,GAAG,GAAG,mBAAmB,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC","sourcesContent":["import { Command } from \"./command.ts\";\nimport { type ClientCommandContext, clientCommand } from \"./commands/client.ts\";\nimport { type ServerCommandContext, serverCommand } from \"./commands/server.ts\";\n\ninterface ExperimentalCommandGroup {\n\treadonly command: \"experimental\";\n}\n\nexport type CliContext = ServerCommandContext & ClientCommandContext;\n\nconst experimentalCommand = new Command<ExperimentalCommandGroup, CliContext>(\"experimental\").build(() => ({\n\tok: false,\n\terrors: [\"Expected experimental command: server or client\"],\n}));\n\nexport const cli = experimentalCommand.command(serverCommand).command(clientCommand);\n"]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type ServerId } from "@earendil-works/pi-protocol";
|
|
2
|
-
import { type ParsedCommandInput } from "./command.ts";
|
|
3
|
-
export type AuthInput = {
|
|
4
|
-
readonly type: "token";
|
|
5
|
-
readonly token: string;
|
|
6
|
-
} | {
|
|
7
|
-
readonly type: "file";
|
|
8
|
-
readonly path: string;
|
|
9
|
-
};
|
|
10
|
-
interface UnixTransportAddress {
|
|
11
|
-
readonly transport: "unix";
|
|
12
|
-
readonly path: string;
|
|
13
|
-
}
|
|
14
|
-
interface RadiusTransportAddress {
|
|
15
|
-
readonly transport: "radius";
|
|
16
|
-
readonly serverId: ServerId;
|
|
17
|
-
}
|
|
18
|
-
export type TransportAddress = UnixTransportAddress | RadiusTransportAddress;
|
|
19
|
-
export declare const authTokenOption: import("./command.ts").CommandOption<string>;
|
|
20
|
-
export declare const authTokenFileOption: import("./command.ts").CommandOption<string>;
|
|
21
|
-
export declare const connectOption: import("./command.ts").CommandOption<TransportAddress>;
|
|
22
|
-
export declare function parseAuth(input: ParsedCommandInput): {
|
|
23
|
-
auth?: AuthInput;
|
|
24
|
-
errors: string[];
|
|
25
|
-
};
|
|
26
|
-
export declare function unsupportedOptions(command: string, input: ParsedCommandInput): string[];
|
|
27
|
-
export {};
|
|
28
|
-
//# sourceMappingURL=command-options.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-options.d.ts","sourceRoot":"","sources":["../../../src/cli/experimental/command-options.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,KAAK,kBAAkB,EAA6B,MAAM,cAAc,CAAC;AAElF,MAAM,MAAM,SAAS,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpD,UAAU,oBAAoB;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,sBAAsB;IAC/B,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC5B;AAED,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,GAAG,sBAAsB,CAAC;AAE7E,eAAO,MAAM,eAAe,8CAA+B,CAAC;AAC5D,eAAO,MAAM,mBAAmB,8CAAoC,CAAC;AAmErE,eAAO,MAAM,aAAa,wDAKxB,CAAC;AAEH,wBAAgB,SAAS,CAAC,KAAK,EAAE,kBAAkB,GAAG;IAAE,IAAI,CAAC,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAK3F;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,MAAM,EAAE,CAGvF","sourcesContent":["import { posix } from \"node:path\";\nimport { isServerId, type ServerId } from \"@earendil-works/pi-protocol\";\nimport { type ParsedCommandInput, stringOption, valueOption } from \"./command.ts\";\n\nexport type AuthInput =\n\t| { readonly type: \"token\"; readonly token: string }\n\t| { readonly type: \"file\"; readonly path: string };\n\ninterface UnixTransportAddress {\n\treadonly transport: \"unix\";\n\treadonly path: string;\n}\n\ninterface RadiusTransportAddress {\n\treadonly transport: \"radius\";\n\treadonly serverId: ServerId;\n}\n\nexport type TransportAddress = UnixTransportAddress | RadiusTransportAddress;\n\nexport const authTokenOption = stringOption(\"--auth-token\");\nexport const authTokenFileOption = stringOption(\"--auth-token-file\");\n\nfunction parseAuthInput(options: { readonly authToken?: string; readonly authTokenFile?: string }): {\n\tauth?: AuthInput;\n\terrors: string[];\n} {\n\tif (options.authToken !== undefined && options.authTokenFile !== undefined) {\n\t\treturn { errors: [\"--auth-token and --auth-token-file are mutually exclusive\"] };\n\t}\n\tif (options.authToken !== undefined) {\n\t\treturn { auth: { type: \"token\", token: options.authToken }, errors: [] };\n\t}\n\tif (options.authTokenFile !== undefined) {\n\t\treturn { auth: { type: \"file\", path: options.authTokenFile }, errors: [] };\n\t}\n\treturn { errors: [] };\n}\n\nfunction parseTransportAddress(value: string): { address?: TransportAddress; error?: string } {\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(value);\n\t} catch {\n\t\treturn { error: `Invalid --connect address \"${value}\"` };\n\t}\n\tif (url.protocol === \"radius:\") {\n\t\tif (\n\t\t\turl.username ||\n\t\t\turl.password ||\n\t\t\turl.port ||\n\t\t\t(url.pathname !== \"\" && url.pathname !== \"/\") ||\n\t\t\turl.search ||\n\t\t\turl.hash ||\n\t\t\tvalue !== `radius://${url.hostname}${url.pathname}`\n\t\t) {\n\t\t\treturn { error: `Invalid --connect address \"${value}\"` };\n\t\t}\n\t\tconst serverId = url.hostname;\n\t\tif (!isServerId(serverId)) {\n\t\t\treturn { error: \"Radius transport address requires a lowercase UUIDv4 server ID\" };\n\t\t}\n\t\treturn { address: { transport: \"radius\", serverId } };\n\t}\n\tif (url.protocol !== \"unix:\") return { error: `Unsupported --connect transport \"${url.protocol}\"` };\n\tif (url.hostname || url.port || url.username || url.password) {\n\t\treturn { error: \"Unix transport address must not include an authority\" };\n\t}\n\tif (\n\t\t!value.startsWith(\"unix:///\") ||\n\t\tvalue.startsWith(\"unix:////\") ||\n\t\tvalue.includes(\"?\") ||\n\t\tvalue.includes(\"#\") ||\n\t\turl.href !== value\n\t) {\n\t\treturn { error: `Invalid --connect address \"${value}\"` };\n\t}\n\tlet path: string;\n\ttry {\n\t\tpath = decodeURIComponent(url.pathname);\n\t} catch {\n\t\treturn { error: `Invalid --connect address \"${value}\"` };\n\t}\n\tif (path.includes(\"\\0\")) return { error: `Invalid --connect address \"${value}\"` };\n\tif (!posix.isAbsolute(path)) return { error: \"Unix transport address requires an absolute path\" };\n\treturn { address: { transport: \"unix\", path } };\n}\n\nexport const connectOption = valueOption(\"--connect\", (value) => {\n\tconst result = parseTransportAddress(value);\n\treturn result.address\n\t\t? { ok: true, value: result.address }\n\t\t: { ok: false, error: result.error ?? `Invalid --connect address \"${value}\"` };\n});\n\nexport function parseAuth(input: ParsedCommandInput): { auth?: AuthInput; errors: string[] } {\n\treturn parseAuthInput({\n\t\tauthToken: input.value(authTokenOption),\n\t\tauthTokenFile: input.value(authTokenFileOption),\n\t});\n}\n\nexport function unsupportedOptions(command: string, input: ParsedCommandInput): string[] {\n\tif (input.remainingArgs.length === 0) return [];\n\treturn [`The experimental ${command} command does not support existing CLI options yet`];\n}\n"]}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { posix } from "node:path";
|
|
2
|
-
import { isServerId } from "@earendil-works/pi-protocol";
|
|
3
|
-
import { stringOption, valueOption } from "./command.js";
|
|
4
|
-
export const authTokenOption = stringOption("--auth-token");
|
|
5
|
-
export const authTokenFileOption = stringOption("--auth-token-file");
|
|
6
|
-
function parseAuthInput(options) {
|
|
7
|
-
if (options.authToken !== undefined && options.authTokenFile !== undefined) {
|
|
8
|
-
return { errors: ["--auth-token and --auth-token-file are mutually exclusive"] };
|
|
9
|
-
}
|
|
10
|
-
if (options.authToken !== undefined) {
|
|
11
|
-
return { auth: { type: "token", token: options.authToken }, errors: [] };
|
|
12
|
-
}
|
|
13
|
-
if (options.authTokenFile !== undefined) {
|
|
14
|
-
return { auth: { type: "file", path: options.authTokenFile }, errors: [] };
|
|
15
|
-
}
|
|
16
|
-
return { errors: [] };
|
|
17
|
-
}
|
|
18
|
-
function parseTransportAddress(value) {
|
|
19
|
-
let url;
|
|
20
|
-
try {
|
|
21
|
-
url = new URL(value);
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
return { error: `Invalid --connect address "${value}"` };
|
|
25
|
-
}
|
|
26
|
-
if (url.protocol === "radius:") {
|
|
27
|
-
if (url.username ||
|
|
28
|
-
url.password ||
|
|
29
|
-
url.port ||
|
|
30
|
-
(url.pathname !== "" && url.pathname !== "/") ||
|
|
31
|
-
url.search ||
|
|
32
|
-
url.hash ||
|
|
33
|
-
value !== `radius://${url.hostname}${url.pathname}`) {
|
|
34
|
-
return { error: `Invalid --connect address "${value}"` };
|
|
35
|
-
}
|
|
36
|
-
const serverId = url.hostname;
|
|
37
|
-
if (!isServerId(serverId)) {
|
|
38
|
-
return { error: "Radius transport address requires a lowercase UUIDv4 server ID" };
|
|
39
|
-
}
|
|
40
|
-
return { address: { transport: "radius", serverId } };
|
|
41
|
-
}
|
|
42
|
-
if (url.protocol !== "unix:")
|
|
43
|
-
return { error: `Unsupported --connect transport "${url.protocol}"` };
|
|
44
|
-
if (url.hostname || url.port || url.username || url.password) {
|
|
45
|
-
return { error: "Unix transport address must not include an authority" };
|
|
46
|
-
}
|
|
47
|
-
if (!value.startsWith("unix:///") ||
|
|
48
|
-
value.startsWith("unix:////") ||
|
|
49
|
-
value.includes("?") ||
|
|
50
|
-
value.includes("#") ||
|
|
51
|
-
url.href !== value) {
|
|
52
|
-
return { error: `Invalid --connect address "${value}"` };
|
|
53
|
-
}
|
|
54
|
-
let path;
|
|
55
|
-
try {
|
|
56
|
-
path = decodeURIComponent(url.pathname);
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
return { error: `Invalid --connect address "${value}"` };
|
|
60
|
-
}
|
|
61
|
-
if (path.includes("\0"))
|
|
62
|
-
return { error: `Invalid --connect address "${value}"` };
|
|
63
|
-
if (!posix.isAbsolute(path))
|
|
64
|
-
return { error: "Unix transport address requires an absolute path" };
|
|
65
|
-
return { address: { transport: "unix", path } };
|
|
66
|
-
}
|
|
67
|
-
export const connectOption = valueOption("--connect", (value) => {
|
|
68
|
-
const result = parseTransportAddress(value);
|
|
69
|
-
return result.address
|
|
70
|
-
? { ok: true, value: result.address }
|
|
71
|
-
: { ok: false, error: result.error ?? `Invalid --connect address "${value}"` };
|
|
72
|
-
});
|
|
73
|
-
export function parseAuth(input) {
|
|
74
|
-
return parseAuthInput({
|
|
75
|
-
authToken: input.value(authTokenOption),
|
|
76
|
-
authTokenFile: input.value(authTokenFileOption),
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
export function unsupportedOptions(command, input) {
|
|
80
|
-
if (input.remainingArgs.length === 0)
|
|
81
|
-
return [];
|
|
82
|
-
return [`The experimental ${command} command does not support existing CLI options yet`];
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=command-options.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-options.js","sourceRoot":"","sources":["../../../src/cli/experimental/command-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,UAAU,EAAiB,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAA2B,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAkBlF,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;AAC5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAC,mBAAmB,CAAC,CAAC;AAErE,SAAS,cAAc,CAAC,OAAyE,EAG/F;IACD,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;QAC5E,OAAO,EAAE,MAAM,EAAE,CAAC,2DAA2D,CAAC,EAAE,CAAC;IAClF,CAAC;IACD,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAC1E,CAAC;IACD,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;QACzC,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAC5E,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AAAA,CACtB;AAED,SAAS,qBAAqB,CA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S,CAAC,KAAyB,EAA0C;IAC5F,OAAO,cAAc,CAAC;QACrB,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,eAAe,CAAC;QACvC,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC;KAC/C,CAAC,CAAC;AAAA,CACH;AAED,MAAM,UAAU,kBAAkB,CAAC,OAAe,EAAE,KAAyB,EAAY;IACxF,IAAI,KAAK,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAChD,OAAO,CAAC,oBAAoB,OAAO,oDAAoD,CAAC,CAAC;AAAA,CACzF","sourcesContent":["import { posix } from \"node:path\";\nimport { isServerId, type ServerId } from \"@earendil-works/pi-protocol\";\nimport { type ParsedCommandInput, stringOption, valueOption } from \"./command.ts\";\n\nexport type AuthInput =\n\t| { readonly type: \"token\"; readonly token: string }\n\t| { readonly type: \"file\"; readonly path: string };\n\ninterface UnixTransportAddress {\n\treadonly transport: \"unix\";\n\treadonly path: string;\n}\n\ninterface RadiusTransportAddress {\n\treadonly transport: \"radius\";\n\treadonly serverId: ServerId;\n}\n\nexport type TransportAddress = UnixTransportAddress | RadiusTransportAddress;\n\nexport const authTokenOption = stringOption(\"--auth-token\");\nexport const authTokenFileOption = stringOption(\"--auth-token-file\");\n\nfunction parseAuthInput(options: { readonly authToken?: string; readonly authTokenFile?: string }): {\n\tauth?: AuthInput;\n\terrors: string[];\n} {\n\tif (options.authToken !== undefined && options.authTokenFile !== undefined) {\n\t\treturn { errors: [\"--auth-token and --auth-token-file are mutually exclusive\"] };\n\t}\n\tif (options.authToken !== undefined) {\n\t\treturn { auth: { type: \"token\", token: options.authToken }, errors: [] };\n\t}\n\tif (options.authTokenFile !== undefined) {\n\t\treturn { auth: { type: \"file\", path: options.authTokenFile }, errors: [] };\n\t}\n\treturn { errors: [] };\n}\n\nfunction parseTransportAddress(value: string): { address?: TransportAddress; error?: string } {\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(value);\n\t} catch {\n\t\treturn { error: `Invalid --connect address \"${value}\"` };\n\t}\n\tif (url.protocol === \"radius:\") {\n\t\tif (\n\t\t\turl.username ||\n\t\t\turl.password ||\n\t\t\turl.port ||\n\t\t\t(url.pathname !== \"\" && url.pathname !== \"/\") ||\n\t\t\turl.search ||\n\t\t\turl.hash ||\n\t\t\tvalue !== `radius://${url.hostname}${url.pathname}`\n\t\t) {\n\t\t\treturn { error: `Invalid --connect address \"${value}\"` };\n\t\t}\n\t\tconst serverId = url.hostname;\n\t\tif (!isServerId(serverId)) {\n\t\t\treturn { error: \"Radius transport address requires a lowercase UUIDv4 server ID\" };\n\t\t}\n\t\treturn { address: { transport: \"radius\", serverId } };\n\t}\n\tif (url.protocol !== \"unix:\") return { error: `Unsupported --connect transport \"${url.protocol}\"` };\n\tif (url.hostname || url.port || url.username || url.password) {\n\t\treturn { error: \"Unix transport address must not include an authority\" };\n\t}\n\tif (\n\t\t!value.startsWith(\"unix:///\") ||\n\t\tvalue.startsWith(\"unix:////\") ||\n\t\tvalue.includes(\"?\") ||\n\t\tvalue.includes(\"#\") ||\n\t\turl.href !== value\n\t) {\n\t\treturn { error: `Invalid --connect address \"${value}\"` };\n\t}\n\tlet path: string;\n\ttry {\n\t\tpath = decodeURIComponent(url.pathname);\n\t} catch {\n\t\treturn { error: `Invalid --connect address \"${value}\"` };\n\t}\n\tif (path.includes(\"\\0\")) return { error: `Invalid --connect address \"${value}\"` };\n\tif (!posix.isAbsolute(path)) return { error: \"Unix transport address requires an absolute path\" };\n\treturn { address: { transport: \"unix\", path } };\n}\n\nexport const connectOption = valueOption(\"--connect\", (value) => {\n\tconst result = parseTransportAddress(value);\n\treturn result.address\n\t\t? { ok: true, value: result.address }\n\t\t: { ok: false, error: result.error ?? `Invalid --connect address \"${value}\"` };\n});\n\nexport function parseAuth(input: ParsedCommandInput): { auth?: AuthInput; errors: string[] } {\n\treturn parseAuthInput({\n\t\tauthToken: input.value(authTokenOption),\n\t\tauthTokenFile: input.value(authTokenFileOption),\n\t});\n}\n\nexport function unsupportedOptions(command: string, input: ParsedCommandInput): string[] {\n\tif (input.remainingArgs.length === 0) return [];\n\treturn [`The experimental ${command} command does not support existing CLI options yet`];\n}\n"]}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
export interface NamedCommandInvocation {
|
|
2
|
-
readonly command: string;
|
|
3
|
-
}
|
|
4
|
-
export type CommandParseResult<TInvocation extends NamedCommandInvocation = NamedCommandInvocation> = {
|
|
5
|
-
readonly ok: true;
|
|
6
|
-
readonly command: TInvocation;
|
|
7
|
-
} | {
|
|
8
|
-
readonly ok: false;
|
|
9
|
-
readonly errors: readonly string[];
|
|
10
|
-
};
|
|
11
|
-
export type CommandExecutionResult<TInvocation extends NamedCommandInvocation = NamedCommandInvocation> = {
|
|
12
|
-
readonly ok: true;
|
|
13
|
-
readonly command: TInvocation;
|
|
14
|
-
} | {
|
|
15
|
-
readonly ok: false;
|
|
16
|
-
readonly errors: readonly string[];
|
|
17
|
-
};
|
|
18
|
-
export type CommandOptionParseResult<TValue> = {
|
|
19
|
-
readonly ok: true;
|
|
20
|
-
readonly value: TValue;
|
|
21
|
-
} | {
|
|
22
|
-
readonly ok: false;
|
|
23
|
-
readonly error: string;
|
|
24
|
-
};
|
|
25
|
-
export interface CommandOption<TValue> {
|
|
26
|
-
readonly name: `-${string}`;
|
|
27
|
-
readonly flag?: boolean;
|
|
28
|
-
readonly repeatable?: boolean;
|
|
29
|
-
parse(value: string): CommandOptionParseResult<TValue>;
|
|
30
|
-
}
|
|
31
|
-
export declare function valueOption<TValue>(name: `-${string}`, parse: (value: string) => CommandOptionParseResult<TValue>, options?: {
|
|
32
|
-
readonly repeatable?: boolean;
|
|
33
|
-
}): CommandOption<TValue>;
|
|
34
|
-
export declare function stringOption(name: `-${string}`, options?: {
|
|
35
|
-
readonly repeatable?: boolean;
|
|
36
|
-
}): CommandOption<string>;
|
|
37
|
-
export declare function flagOption(name: `-${string}`): CommandOption<boolean>;
|
|
38
|
-
export interface ParsedCommandInput {
|
|
39
|
-
readonly remainingArgs: readonly string[];
|
|
40
|
-
value<TValue>(option: CommandOption<TValue>): TValue | undefined;
|
|
41
|
-
values<TValue>(option: CommandOption<TValue>): readonly TValue[];
|
|
42
|
-
}
|
|
43
|
-
export type CommandBuildResult<TInvocation extends NamedCommandInvocation> = {
|
|
44
|
-
readonly ok: true;
|
|
45
|
-
readonly command: TInvocation;
|
|
46
|
-
} | {
|
|
47
|
-
readonly ok: false;
|
|
48
|
-
readonly errors: readonly string[];
|
|
49
|
-
};
|
|
50
|
-
type CommandBuilder<TInvocation extends NamedCommandInvocation> = (input: ParsedCommandInput) => CommandBuildResult<TInvocation>;
|
|
51
|
-
type CommandAction<TInvocation extends NamedCommandInvocation, TContext> = (command: TInvocation, context: TContext) => void | Promise<void>;
|
|
52
|
-
export declare class Command<TOwnInvocation extends NamedCommandInvocation, TContext, TInvocation extends NamedCommandInvocation = TOwnInvocation> {
|
|
53
|
-
readonly name: string;
|
|
54
|
-
private readonly options;
|
|
55
|
-
private readonly subcommands;
|
|
56
|
-
private builder?;
|
|
57
|
-
private commandAction?;
|
|
58
|
-
constructor(name: string);
|
|
59
|
-
option<TValue>(option: CommandOption<TValue>): this;
|
|
60
|
-
build(builder: CommandBuilder<TOwnInvocation>): this;
|
|
61
|
-
action(action: CommandAction<TOwnInvocation, TContext>): this;
|
|
62
|
-
command<TSubcommandOwnInvocation extends NamedCommandInvocation, TSubcommandContext, TSubcommandInvocation extends NamedCommandInvocation>(command: Command<TSubcommandOwnInvocation, TSubcommandContext, TSubcommandInvocation>): Command<TOwnInvocation, TContext & TSubcommandContext, TInvocation | TSubcommandInvocation>;
|
|
63
|
-
parse(argv: readonly string[]): CommandParseResult<TInvocation>;
|
|
64
|
-
execute(argv: readonly string[], context: TContext): Promise<CommandExecutionResult<TInvocation>>;
|
|
65
|
-
private select;
|
|
66
|
-
private parseOwn;
|
|
67
|
-
private parseOptions;
|
|
68
|
-
}
|
|
69
|
-
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AWtG;IAED,OAAO,CAAC,MAAM;IAOd,OAAO,CAAC,QAAQ;IAehB,OAAO,CAAC,YAAY;CA2DpB","sourcesContent":["export interface NamedCommandInvocation {\n\treadonly command: string;\n}\n\nexport type CommandParseResult<TInvocation extends NamedCommandInvocation = NamedCommandInvocation> =\n\t| { readonly ok: true; readonly command: TInvocation }\n\t| { readonly ok: false; readonly errors: readonly string[] };\n\nexport type CommandExecutionResult<TInvocation extends NamedCommandInvocation = NamedCommandInvocation> =\n\t| { readonly ok: true; readonly command: TInvocation }\n\t| { readonly ok: false; readonly errors: readonly string[] };\n\nexport type CommandOptionParseResult<TValue> =\n\t| { readonly ok: true; readonly value: TValue }\n\t| { readonly ok: false; readonly error: string };\n\nexport interface CommandOption<TValue> {\n\treadonly name: `-${string}`;\n\treadonly flag?: boolean;\n\treadonly repeatable?: boolean;\n\tparse(value: string): CommandOptionParseResult<TValue>;\n}\n\nexport function valueOption<TValue>(\n\tname: `-${string}`,\n\tparse: (value: string) => CommandOptionParseResult<TValue>,\n\toptions: { readonly repeatable?: boolean } = {},\n): CommandOption<TValue> {\n\treturn { name, parse, ...options };\n}\n\nexport function stringOption(\n\tname: `-${string}`,\n\toptions: { readonly repeatable?: boolean } = {},\n): CommandOption<string> {\n\treturn valueOption(name, (value) => ({ ok: true, value }), options);\n}\n\nexport function flagOption(name: `-${string}`): CommandOption<boolean> {\n\treturn { name, flag: true, parse: () => ({ ok: true, value: true }) };\n}\n\nexport interface ParsedCommandInput {\n\treadonly remainingArgs: readonly string[];\n\tvalue<TValue>(option: CommandOption<TValue>): TValue | undefined;\n\tvalues<TValue>(option: CommandOption<TValue>): readonly TValue[];\n}\n\nexport type CommandBuildResult<TInvocation extends NamedCommandInvocation> =\n\t| { readonly ok: true; readonly command: TInvocation }\n\t| { readonly ok: false; readonly errors: readonly string[] };\n\ninterface MutableParsedCommandInput {\n\treadonly values: Map<string, unknown[]>;\n\treadonly remainingArgs: string[];\n\treadonly errors: string[];\n}\n\ntype CommandBuilder<TInvocation extends NamedCommandInvocation> = (\n\tinput: ParsedCommandInput,\n) => CommandBuildResult<TInvocation>;\n\ntype CommandAction<TInvocation extends NamedCommandInvocation, TContext> = (\n\tcommand: TInvocation,\n\tcontext: TContext,\n) => void | Promise<void>;\n\ninterface RegisteredCommand {\n\tparse(argv: readonly string[]): CommandParseResult;\n\texecute(argv: readonly string[], context: unknown): Promise<CommandExecutionResult>;\n}\n\nexport class Command<\n\tTOwnInvocation extends NamedCommandInvocation,\n\tTContext,\n\tTInvocation extends NamedCommandInvocation = TOwnInvocation,\n> {\n\treadonly name: string;\n\tprivate readonly options = new Map<string, CommandOption<unknown>>();\n\tprivate readonly subcommands = new Map<string, RegisteredCommand>();\n\tprivate builder?: CommandBuilder<TOwnInvocation>;\n\tprivate commandAction?: CommandAction<TOwnInvocation, TContext>;\n\n\tconstructor(name: string) {\n\t\tthis.name = name;\n\t}\n\n\toption<TValue>(option: CommandOption<TValue>): this {\n\t\tif (this.options.has(option.name)) {\n\t\t\tthrow new Error(`Option ${option.name} is already registered for ${this.name}`);\n\t\t}\n\t\tthis.options.set(option.name, option);\n\t\treturn this;\n\t}\n\n\tbuild(builder: CommandBuilder<TOwnInvocation>): this {\n\t\tthis.builder = builder;\n\t\treturn this;\n\t}\n\n\taction(action: CommandAction<TOwnInvocation, TContext>): this {\n\t\tthis.commandAction = action;\n\t\treturn this;\n\t}\n\n\tcommand<\n\t\tTSubcommandOwnInvocation extends NamedCommandInvocation,\n\t\tTSubcommandContext,\n\t\tTSubcommandInvocation extends NamedCommandInvocation,\n\t>(\n\t\tcommand: Command<TSubcommandOwnInvocation, TSubcommandContext, TSubcommandInvocation>,\n\t): Command<TOwnInvocation, TContext & TSubcommandContext, TInvocation | TSubcommandInvocation> {\n\t\tif (this.subcommands.has(command.name)) throw new Error(`Command ${command.name} is already registered`);\n\t\tthis.subcommands.set(command.name, {\n\t\t\tparse: (argv) => command.parse(argv),\n\t\t\texecute: (argv, context) => command.execute(argv, context as TSubcommandContext),\n\t\t});\n\t\treturn this as unknown as Command<\n\t\t\tTOwnInvocation,\n\t\t\tTContext & TSubcommandContext,\n\t\t\tTInvocation | TSubcommandInvocation\n\t\t>;\n\t}\n\n\tparse(argv: readonly string[]): CommandParseResult<TInvocation> {\n\t\tconst selected = this.select(argv);\n\t\tif (selected) return selected.command.parse(selected.argv) as CommandParseResult<TInvocation>;\n\t\treturn this.parseOwn(argv) as CommandParseResult<TInvocation>;\n\t}\n\n\tasync execute(argv: readonly string[], context: TContext): Promise<CommandExecutionResult<TInvocation>> {\n\t\tconst selected = this.select(argv);\n\t\tif (selected) {\n\t\t\treturn selected.command.execute(selected.argv, context) as Promise<CommandExecutionResult<TInvocation>>;\n\t\t}\n\n\t\tconst parsed = this.parseOwn(argv);\n\t\tif (!parsed.ok) return parsed;\n\t\tif (!this.commandAction) throw new Error(`Command ${this.name} does not define an action`);\n\t\tawait this.commandAction(parsed.command, context);\n\t\treturn { ok: true, command: parsed.command as unknown as TInvocation };\n\t}\n\n\tprivate select(argv: readonly string[]): { command: RegisteredCommand; argv: readonly string[] } | undefined {\n\t\tconst candidate = argv[0];\n\t\tif (candidate === undefined) return undefined;\n\t\tconst command = this.subcommands.get(candidate);\n\t\treturn command ? { command, argv: argv.slice(1) } : undefined;\n\t}\n\n\tprivate parseOwn(argv: readonly string[]): CommandParseResult<TOwnInvocation> {\n\t\tif (!this.builder) throw new Error(`Command ${this.name} does not define a builder`);\n\t\tconst parsed = this.parseOptions(argv);\n\t\tconst input: ParsedCommandInput = {\n\t\t\tremainingArgs: parsed.remainingArgs,\n\t\t\tvalue: <TValue>(option: CommandOption<TValue>) => parsed.values.get(option.name)?.[0] as TValue | undefined,\n\t\t\tvalues: <TValue>(option: CommandOption<TValue>) => (parsed.values.get(option.name) ?? []) as readonly TValue[],\n\t\t};\n\t\tconst built = this.builder(input);\n\t\tconst errors = [...parsed.errors, ...(built.ok ? [] : built.errors)];\n\t\tif (errors.length > 0) return { ok: false, errors };\n\t\tif (!built.ok) throw new Error(`Command ${this.name} failed without an error`);\n\t\treturn { ok: true, command: built.command };\n\t}\n\n\tprivate parseOptions(argv: readonly string[]): MutableParsedCommandInput {\n\t\tconst parsed: MutableParsedCommandInput = {\n\t\t\tvalues: new Map(),\n\t\t\tremainingArgs: [],\n\t\t\terrors: [],\n\t\t};\n\t\tfor (let index = 0; index < argv.length; index++) {\n\t\t\tconst argument = argv[index]!;\n\t\t\tif (argument === \"--\") {\n\t\t\t\tparsed.remainingArgs.push(...argv.slice(index));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst equals = argument.indexOf(\"=\");\n\t\t\tconst name = equals === -1 ? argument : argument.slice(0, equals);\n\t\t\tconst option = this.options.get(name);\n\t\t\tif (!option) {\n\t\t\t\tparsed.remainingArgs.push(...argv.slice(index));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tlet value: string;\n\t\t\tif (option.flag === true) {\n\t\t\t\tif (equals !== -1) {\n\t\t\t\t\tparsed.errors.push(`${name} does not take a value`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tvalue = \"\";\n\t\t\t} else {\n\t\t\t\tlet candidate = equals === -1 ? undefined : argument.slice(equals + 1);\n\t\t\t\tif (candidate === undefined) {\n\t\t\t\t\tconst next = argv[index + 1];\n\t\t\t\t\tif (next !== undefined && !next.startsWith(\"-\")) {\n\t\t\t\t\t\tcandidate = next;\n\t\t\t\t\t\tindex++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (candidate === undefined || candidate === \"\") {\n\t\t\t\t\tparsed.errors.push(`${name} requires a value`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tvalue = candidate;\n\t\t\t}\n\n\t\t\tconst values = parsed.values.get(name) ?? [];\n\t\t\tif (values.length > 0 && option.repeatable !== true) {\n\t\t\t\tparsed.errors.push(`${name} may only be specified once`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = option.parse(value);\n\t\t\tif (!result.ok) {\n\t\t\t\tparsed.errors.push(result.error);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvalues.push(result.value);\n\t\t\tparsed.values.set(name, values);\n\t\t}\n\t\treturn parsed;\n\t}\n}\n"]}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
export function valueOption(name, parse, options = {}) {
|
|
2
|
-
return { name, parse, ...options };
|
|
3
|
-
}
|
|
4
|
-
export function stringOption(name, options = {}) {
|
|
5
|
-
return valueOption(name, (value) => ({ ok: true, value }), options);
|
|
6
|
-
}
|
|
7
|
-
export function flagOption(name) {
|
|
8
|
-
return { name, flag: true, parse: () => ({ ok: true, value: true }) };
|
|
9
|
-
}
|
|
10
|
-
export class Command {
|
|
11
|
-
name;
|
|
12
|
-
options = new Map();
|
|
13
|
-
subcommands = new Map();
|
|
14
|
-
builder;
|
|
15
|
-
commandAction;
|
|
16
|
-
constructor(name) {
|
|
17
|
-
this.name = name;
|
|
18
|
-
}
|
|
19
|
-
option(option) {
|
|
20
|
-
if (this.options.has(option.name)) {
|
|
21
|
-
throw new Error(`Option ${option.name} is already registered for ${this.name}`);
|
|
22
|
-
}
|
|
23
|
-
this.options.set(option.name, option);
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
build(builder) {
|
|
27
|
-
this.builder = builder;
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
action(action) {
|
|
31
|
-
this.commandAction = action;
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
command(command) {
|
|
35
|
-
if (this.subcommands.has(command.name))
|
|
36
|
-
throw new Error(`Command ${command.name} is already registered`);
|
|
37
|
-
this.subcommands.set(command.name, {
|
|
38
|
-
parse: (argv) => command.parse(argv),
|
|
39
|
-
execute: (argv, context) => command.execute(argv, context),
|
|
40
|
-
});
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
parse(argv) {
|
|
44
|
-
const selected = this.select(argv);
|
|
45
|
-
if (selected)
|
|
46
|
-
return selected.command.parse(selected.argv);
|
|
47
|
-
return this.parseOwn(argv);
|
|
48
|
-
}
|
|
49
|
-
async execute(argv, context) {
|
|
50
|
-
const selected = this.select(argv);
|
|
51
|
-
if (selected) {
|
|
52
|
-
return selected.command.execute(selected.argv, context);
|
|
53
|
-
}
|
|
54
|
-
const parsed = this.parseOwn(argv);
|
|
55
|
-
if (!parsed.ok)
|
|
56
|
-
return parsed;
|
|
57
|
-
if (!this.commandAction)
|
|
58
|
-
throw new Error(`Command ${this.name} does not define an action`);
|
|
59
|
-
await this.commandAction(parsed.command, context);
|
|
60
|
-
return { ok: true, command: parsed.command };
|
|
61
|
-
}
|
|
62
|
-
select(argv) {
|
|
63
|
-
const candidate = argv[0];
|
|
64
|
-
if (candidate === undefined)
|
|
65
|
-
return undefined;
|
|
66
|
-
const command = this.subcommands.get(candidate);
|
|
67
|
-
return command ? { command, argv: argv.slice(1) } : undefined;
|
|
68
|
-
}
|
|
69
|
-
parseOwn(argv) {
|
|
70
|
-
if (!this.builder)
|
|
71
|
-
throw new Error(`Command ${this.name} does not define a builder`);
|
|
72
|
-
const parsed = this.parseOptions(argv);
|
|
73
|
-
const input = {
|
|
74
|
-
remainingArgs: parsed.remainingArgs,
|
|
75
|
-
value: (option) => parsed.values.get(option.name)?.[0],
|
|
76
|
-
values: (option) => (parsed.values.get(option.name) ?? []),
|
|
77
|
-
};
|
|
78
|
-
const built = this.builder(input);
|
|
79
|
-
const errors = [...parsed.errors, ...(built.ok ? [] : built.errors)];
|
|
80
|
-
if (errors.length > 0)
|
|
81
|
-
return { ok: false, errors };
|
|
82
|
-
if (!built.ok)
|
|
83
|
-
throw new Error(`Command ${this.name} failed without an error`);
|
|
84
|
-
return { ok: true, command: built.command };
|
|
85
|
-
}
|
|
86
|
-
parseOptions(argv) {
|
|
87
|
-
const parsed = {
|
|
88
|
-
values: new Map(),
|
|
89
|
-
remainingArgs: [],
|
|
90
|
-
errors: [],
|
|
91
|
-
};
|
|
92
|
-
for (let index = 0; index < argv.length; index++) {
|
|
93
|
-
const argument = argv[index];
|
|
94
|
-
if (argument === "--") {
|
|
95
|
-
parsed.remainingArgs.push(...argv.slice(index));
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
const equals = argument.indexOf("=");
|
|
99
|
-
const name = equals === -1 ? argument : argument.slice(0, equals);
|
|
100
|
-
const option = this.options.get(name);
|
|
101
|
-
if (!option) {
|
|
102
|
-
parsed.remainingArgs.push(...argv.slice(index));
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
let value;
|
|
106
|
-
if (option.flag === true) {
|
|
107
|
-
if (equals !== -1) {
|
|
108
|
-
parsed.errors.push(`${name} does not take a value`);
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
value = "";
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
let candidate = equals === -1 ? undefined : argument.slice(equals + 1);
|
|
115
|
-
if (candidate === undefined) {
|
|
116
|
-
const next = argv[index + 1];
|
|
117
|
-
if (next !== undefined && !next.startsWith("-")) {
|
|
118
|
-
candidate = next;
|
|
119
|
-
index++;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (candidate === undefined || candidate === "") {
|
|
123
|
-
parsed.errors.push(`${name} requires a value`);
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
value = candidate;
|
|
127
|
-
}
|
|
128
|
-
const values = parsed.values.get(name) ?? [];
|
|
129
|
-
if (values.length > 0 && option.repeatable !== true) {
|
|
130
|
-
parsed.errors.push(`${name} may only be specified once`);
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
const result = option.parse(value);
|
|
134
|
-
if (!result.ok) {
|
|
135
|
-
parsed.errors.push(result.error);
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
values.push(result.value);
|
|
139
|
-
parsed.values.set(name, values);
|
|
140
|
-
}
|
|
141
|
-
return parsed;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
//# sourceMappingURL=command.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../../src/cli/experimental/command.ts"],"names":[],"mappings":"AAuBA,MAAM,UAAU,WAAW,CAC1B,IAAkB,EAClB,KAA0D,EAC1D,OAAO,GAAsC,EAAE,EACvB;IACxB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC;AAAA,CACnC;AAED,MAAM,UAAU,YAAY,CAC3B,IAAkB,EAClB,OAAO,GAAsC,EAAE,EACvB;IACxB,OAAO,WAAW,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;AAAA,CACpE;AAED,MAAM,UAAU,UAAU,CAAC,IAAkB,EAA0B;IACtE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;AAAA,CACtE;AAgCD,MAAM,OAAO,OAAO;IAKV,IAAI,CAAS;IACL,OAAO,GAAG,IAAI,GAAG,EAAkC,CAAC;IACpD,WAAW,GAAG,IAAI,GAAG,EAA6B,CAAC;IAC5D,OAAO,CAAkC;IACzC,aAAa,CAA2C;IAEhE,YAAY,IAAY,EAAE;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAAA,CACjB;IAED,MAAM,CAAS,MAA6B,EAAQ;QACnD,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,UAAU,MAAM,CAAC,IAAI,8BAA8B,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACjF,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAA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D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,mBAAmB,CAAC,CAAC;oBAC/C,SAAS;gBACV,CAAC;gBACD,KAAK,GAAG,SAAS,CAAC;YACnB,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAC7C,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;gBACrD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,6BAA6B,CAAC,CAAC;gBACzD,SAAS;YACV,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACnC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;gBAChB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACjC,SAAS;YACV,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC1B,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,MAAM,CAAC;IAAA,CACd;CACD","sourcesContent":["export interface NamedCommandInvocation {\n\treadonly command: string;\n}\n\nexport type CommandParseResult<TInvocation extends NamedCommandInvocation = NamedCommandInvocation> =\n\t| { readonly ok: true; readonly command: TInvocation }\n\t| { readonly ok: false; readonly errors: readonly string[] };\n\nexport type CommandExecutionResult<TInvocation extends NamedCommandInvocation = NamedCommandInvocation> =\n\t| { readonly ok: true; readonly command: TInvocation }\n\t| { readonly ok: false; readonly errors: readonly string[] };\n\nexport type CommandOptionParseResult<TValue> =\n\t| { readonly ok: true; readonly value: TValue }\n\t| { readonly ok: false; readonly error: string };\n\nexport interface CommandOption<TValue> {\n\treadonly name: `-${string}`;\n\treadonly flag?: boolean;\n\treadonly repeatable?: boolean;\n\tparse(value: string): CommandOptionParseResult<TValue>;\n}\n\nexport function valueOption<TValue>(\n\tname: `-${string}`,\n\tparse: (value: string) => CommandOptionParseResult<TValue>,\n\toptions: { readonly repeatable?: boolean } = {},\n): CommandOption<TValue> {\n\treturn { name, parse, ...options };\n}\n\nexport function stringOption(\n\tname: `-${string}`,\n\toptions: { readonly repeatable?: boolean } = {},\n): CommandOption<string> {\n\treturn valueOption(name, (value) => ({ ok: true, value }), options);\n}\n\nexport function flagOption(name: `-${string}`): CommandOption<boolean> {\n\treturn { name, flag: true, parse: () => ({ ok: true, value: true }) };\n}\n\nexport interface ParsedCommandInput {\n\treadonly remainingArgs: readonly string[];\n\tvalue<TValue>(option: CommandOption<TValue>): TValue | undefined;\n\tvalues<TValue>(option: CommandOption<TValue>): readonly TValue[];\n}\n\nexport type CommandBuildResult<TInvocation extends NamedCommandInvocation> =\n\t| { readonly ok: true; readonly command: TInvocation }\n\t| { readonly ok: false; readonly errors: readonly string[] };\n\ninterface MutableParsedCommandInput {\n\treadonly values: Map<string, unknown[]>;\n\treadonly remainingArgs: string[];\n\treadonly errors: string[];\n}\n\ntype CommandBuilder<TInvocation extends NamedCommandInvocation> = (\n\tinput: ParsedCommandInput,\n) => CommandBuildResult<TInvocation>;\n\ntype CommandAction<TInvocation extends NamedCommandInvocation, TContext> = (\n\tcommand: TInvocation,\n\tcontext: TContext,\n) => void | Promise<void>;\n\ninterface RegisteredCommand {\n\tparse(argv: readonly string[]): CommandParseResult;\n\texecute(argv: readonly string[], context: unknown): Promise<CommandExecutionResult>;\n}\n\nexport class Command<\n\tTOwnInvocation extends NamedCommandInvocation,\n\tTContext,\n\tTInvocation extends NamedCommandInvocation = TOwnInvocation,\n> {\n\treadonly name: string;\n\tprivate readonly options = new Map<string, CommandOption<unknown>>();\n\tprivate readonly subcommands = new Map<string, RegisteredCommand>();\n\tprivate builder?: CommandBuilder<TOwnInvocation>;\n\tprivate commandAction?: CommandAction<TOwnInvocation, TContext>;\n\n\tconstructor(name: string) {\n\t\tthis.name = name;\n\t}\n\n\toption<TValue>(option: CommandOption<TValue>): this {\n\t\tif (this.options.has(option.name)) {\n\t\t\tthrow new Error(`Option ${option.name} is already registered for ${this.name}`);\n\t\t}\n\t\tthis.options.set(option.name, option);\n\t\treturn this;\n\t}\n\n\tbuild(builder: CommandBuilder<TOwnInvocation>): this {\n\t\tthis.builder = builder;\n\t\treturn this;\n\t}\n\n\taction(action: CommandAction<TOwnInvocation, TContext>): this {\n\t\tthis.commandAction = action;\n\t\treturn this;\n\t}\n\n\tcommand<\n\t\tTSubcommandOwnInvocation extends NamedCommandInvocation,\n\t\tTSubcommandContext,\n\t\tTSubcommandInvocation extends NamedCommandInvocation,\n\t>(\n\t\tcommand: Command<TSubcommandOwnInvocation, TSubcommandContext, TSubcommandInvocation>,\n\t): Command<TOwnInvocation, TContext & TSubcommandContext, TInvocation | TSubcommandInvocation> {\n\t\tif (this.subcommands.has(command.name)) throw new Error(`Command ${command.name} is already registered`);\n\t\tthis.subcommands.set(command.name, {\n\t\t\tparse: (argv) => command.parse(argv),\n\t\t\texecute: (argv, context) => command.execute(argv, context as TSubcommandContext),\n\t\t});\n\t\treturn this as unknown as Command<\n\t\t\tTOwnInvocation,\n\t\t\tTContext & TSubcommandContext,\n\t\t\tTInvocation | TSubcommandInvocation\n\t\t>;\n\t}\n\n\tparse(argv: readonly string[]): CommandParseResult<TInvocation> {\n\t\tconst selected = this.select(argv);\n\t\tif (selected) return selected.command.parse(selected.argv) as CommandParseResult<TInvocation>;\n\t\treturn this.parseOwn(argv) as CommandParseResult<TInvocation>;\n\t}\n\n\tasync execute(argv: readonly string[], context: TContext): Promise<CommandExecutionResult<TInvocation>> {\n\t\tconst selected = this.select(argv);\n\t\tif (selected) {\n\t\t\treturn selected.command.execute(selected.argv, context) as Promise<CommandExecutionResult<TInvocation>>;\n\t\t}\n\n\t\tconst parsed = this.parseOwn(argv);\n\t\tif (!parsed.ok) return parsed;\n\t\tif (!this.commandAction) throw new Error(`Command ${this.name} does not define an action`);\n\t\tawait this.commandAction(parsed.command, context);\n\t\treturn { ok: true, command: parsed.command as unknown as TInvocation };\n\t}\n\n\tprivate select(argv: readonly string[]): { command: RegisteredCommand; argv: readonly string[] } | undefined {\n\t\tconst candidate = argv[0];\n\t\tif (candidate === undefined) return undefined;\n\t\tconst command = this.subcommands.get(candidate);\n\t\treturn command ? { command, argv: argv.slice(1) } : undefined;\n\t}\n\n\tprivate parseOwn(argv: readonly string[]): CommandParseResult<TOwnInvocation> {\n\t\tif (!this.builder) throw new Error(`Command ${this.name} does not define a builder`);\n\t\tconst parsed = this.parseOptions(argv);\n\t\tconst input: ParsedCommandInput = {\n\t\t\tremainingArgs: parsed.remainingArgs,\n\t\t\tvalue: <TValue>(option: CommandOption<TValue>) => parsed.values.get(option.name)?.[0] as TValue | undefined,\n\t\t\tvalues: <TValue>(option: CommandOption<TValue>) => (parsed.values.get(option.name) ?? []) as readonly TValue[],\n\t\t};\n\t\tconst built = this.builder(input);\n\t\tconst errors = [...parsed.errors, ...(built.ok ? [] : built.errors)];\n\t\tif (errors.length > 0) return { ok: false, errors };\n\t\tif (!built.ok) throw new Error(`Command ${this.name} failed without an error`);\n\t\treturn { ok: true, command: built.command };\n\t}\n\n\tprivate parseOptions(argv: readonly string[]): MutableParsedCommandInput {\n\t\tconst parsed: MutableParsedCommandInput = {\n\t\t\tvalues: new Map(),\n\t\t\tremainingArgs: [],\n\t\t\terrors: [],\n\t\t};\n\t\tfor (let index = 0; index < argv.length; index++) {\n\t\t\tconst argument = argv[index]!;\n\t\t\tif (argument === \"--\") {\n\t\t\t\tparsed.remainingArgs.push(...argv.slice(index));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst equals = argument.indexOf(\"=\");\n\t\t\tconst name = equals === -1 ? argument : argument.slice(0, equals);\n\t\t\tconst option = this.options.get(name);\n\t\t\tif (!option) {\n\t\t\t\tparsed.remainingArgs.push(...argv.slice(index));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tlet value: string;\n\t\t\tif (option.flag === true) {\n\t\t\t\tif (equals !== -1) {\n\t\t\t\t\tparsed.errors.push(`${name} does not take a value`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tvalue = \"\";\n\t\t\t} else {\n\t\t\t\tlet candidate = equals === -1 ? undefined : argument.slice(equals + 1);\n\t\t\t\tif (candidate === undefined) {\n\t\t\t\t\tconst next = argv[index + 1];\n\t\t\t\t\tif (next !== undefined && !next.startsWith(\"-\")) {\n\t\t\t\t\t\tcandidate = next;\n\t\t\t\t\t\tindex++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (candidate === undefined || candidate === \"\") {\n\t\t\t\t\tparsed.errors.push(`${name} requires a value`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tvalue = candidate;\n\t\t\t}\n\n\t\t\tconst values = parsed.values.get(name) ?? [];\n\t\t\tif (values.length > 0 && option.repeatable !== true) {\n\t\t\t\tparsed.errors.push(`${name} may only be specified once`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = option.parse(value);\n\t\t\tif (!result.ok) {\n\t\t\t\tparsed.errors.push(result.error);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvalues.push(result.value);\n\t\t\tparsed.values.set(name, values);\n\t\t}\n\t\treturn parsed;\n\t}\n}\n"]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command.ts";
|
|
2
|
-
import { type AuthInput, type TransportAddress } from "../command-options.ts";
|
|
3
|
-
export interface ClientCommand {
|
|
4
|
-
readonly command: "client";
|
|
5
|
-
readonly auth?: AuthInput;
|
|
6
|
-
readonly connect?: TransportAddress;
|
|
7
|
-
readonly sessionId?: string;
|
|
8
|
-
readonly continue?: boolean;
|
|
9
|
-
readonly resume?: boolean;
|
|
10
|
-
readonly provider?: string;
|
|
11
|
-
readonly model?: string;
|
|
12
|
-
readonly pluginPackages?: readonly string[];
|
|
13
|
-
readonly prompt?: string;
|
|
14
|
-
}
|
|
15
|
-
export interface ClientCommandContext {
|
|
16
|
-
runClient(command: ClientCommand): void | Promise<void>;
|
|
17
|
-
}
|
|
18
|
-
export declare const clientCommand: Command<ClientCommand, ClientCommandContext, ClientCommand>;
|
|
19
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/cli/experimental/commands/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA4B,MAAM,eAAe,CAAC;AAClE,OAAO,EACN,KAAK,SAAS,EAKd,KAAK,gBAAgB,EAErB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,oBAAoB;IACpC,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD;AAWD,eAAO,MAAM,aAAa,6DAqDgC,CAAC","sourcesContent":["import { Command, flagOption, stringOption } from \"../command.ts\";\nimport {\n\ttype AuthInput,\n\tauthTokenFileOption,\n\tauthTokenOption,\n\tconnectOption,\n\tparseAuth,\n\ttype TransportAddress,\n\tunsupportedOptions,\n} from \"../command-options.ts\";\n\nexport interface ClientCommand {\n\treadonly command: \"client\";\n\treadonly auth?: AuthInput;\n\treadonly connect?: TransportAddress;\n\treadonly sessionId?: string;\n\treadonly continue?: boolean;\n\treadonly resume?: boolean;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly pluginPackages?: readonly string[];\n\treadonly prompt?: string;\n}\n\nexport interface ClientCommandContext {\n\trunClient(command: ClientCommand): void | Promise<void>;\n}\n\nconst sessionIdOption = stringOption(\"--session-id\");\nconst continueOption = flagOption(\"--continue\");\nconst continueShortOption = flagOption(\"-c\");\nconst resumeOption = flagOption(\"--resume\");\nconst resumeShortOption = flagOption(\"-r\");\nconst providerOption = stringOption(\"--provider\");\nconst modelOption = stringOption(\"--model\");\nconst pluginPackageOption = stringOption(\"-e\", { repeatable: true });\n\nexport const clientCommand = new Command<ClientCommand, ClientCommandContext>(\"client\")\n\t.option(connectOption)\n\t.option(sessionIdOption)\n\t.option(continueOption)\n\t.option(continueShortOption)\n\t.option(resumeOption)\n\t.option(resumeShortOption)\n\t.option(providerOption)\n\t.option(modelOption)\n\t.option(pluginPackageOption)\n\t.option(authTokenOption)\n\t.option(authTokenFileOption)\n\t.build((input) => {\n\t\tconst { auth, errors: authErrors } = parseAuth(input);\n\t\tconst connect = input.value(connectOption);\n\t\tconst sessionId = input.value(sessionIdOption);\n\t\tconst shouldContinue = input.value(continueOption) === true || input.value(continueShortOption) === true;\n\t\tconst shouldResume = input.value(resumeOption) === true || input.value(resumeShortOption) === true;\n\t\tconst provider = input.value(providerOption);\n\t\tconst model = input.value(modelOption);\n\t\tconst pluginPackages = input.values(pluginPackageOption);\n\t\tconst promptArgs = input.remainingArgs[0] === \"--\" ? input.remainingArgs.slice(1) : input.remainingArgs;\n\t\tconst prompt =\n\t\t\tpromptArgs.length === 1 &&\n\t\t\t(input.remainingArgs[0] === \"--\" || !promptArgs[0]!.startsWith(\"-\")) &&\n\t\t\tpromptArgs[0]!.length > 0\n\t\t\t\t? promptArgs[0]\n\t\t\t\t: undefined;\n\t\tconst modelErrors = provider !== undefined && model === undefined ? [\"--provider requires --model\"] : [];\n\t\tconst sessionSelectionErrors =\n\t\t\t[sessionId !== undefined, shouldContinue, shouldResume].filter(Boolean).length > 1\n\t\t\t\t? [\"--session-id, --continue, and --resume are mutually exclusive\"]\n\t\t\t\t: [];\n\t\tconst unsupportedErrors =\n\t\t\tinput.remainingArgs.length === 0 || prompt !== undefined ? [] : unsupportedOptions(\"client\", input);\n\t\tconst errors = [...authErrors, ...modelErrors, ...sessionSelectionErrors, ...unsupportedErrors];\n\t\tif (errors.length > 0) return { ok: false, errors };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tcommand: {\n\t\t\t\tcommand: \"client\",\n\t\t\t\t...(auth === undefined ? {} : { auth }),\n\t\t\t\t...(connect === undefined ? {} : { connect }),\n\t\t\t\t...(sessionId === undefined ? {} : { sessionId }),\n\t\t\t\t...(shouldContinue ? { continue: true } : {}),\n\t\t\t\t...(shouldResume ? { resume: true } : {}),\n\t\t\t\t...(provider === undefined ? {} : { provider }),\n\t\t\t\t...(model === undefined ? {} : { model }),\n\t\t\t\t...(pluginPackages.length === 0 ? {} : { pluginPackages }),\n\t\t\t\t...(prompt === undefined ? {} : { prompt }),\n\t\t\t},\n\t\t};\n\t})\n\t.action((command, context) => context.runClient(command));\n"]}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Command, flagOption, stringOption } from "../command.js";
|
|
2
|
-
import { authTokenFileOption, authTokenOption, connectOption, parseAuth, unsupportedOptions, } from "../command-options.js";
|
|
3
|
-
const sessionIdOption = stringOption("--session-id");
|
|
4
|
-
const continueOption = flagOption("--continue");
|
|
5
|
-
const continueShortOption = flagOption("-c");
|
|
6
|
-
const resumeOption = flagOption("--resume");
|
|
7
|
-
const resumeShortOption = flagOption("-r");
|
|
8
|
-
const providerOption = stringOption("--provider");
|
|
9
|
-
const modelOption = stringOption("--model");
|
|
10
|
-
const pluginPackageOption = stringOption("-e", { repeatable: true });
|
|
11
|
-
export const clientCommand = new Command("client")
|
|
12
|
-
.option(connectOption)
|
|
13
|
-
.option(sessionIdOption)
|
|
14
|
-
.option(continueOption)
|
|
15
|
-
.option(continueShortOption)
|
|
16
|
-
.option(resumeOption)
|
|
17
|
-
.option(resumeShortOption)
|
|
18
|
-
.option(providerOption)
|
|
19
|
-
.option(modelOption)
|
|
20
|
-
.option(pluginPackageOption)
|
|
21
|
-
.option(authTokenOption)
|
|
22
|
-
.option(authTokenFileOption)
|
|
23
|
-
.build((input) => {
|
|
24
|
-
const { auth, errors: authErrors } = parseAuth(input);
|
|
25
|
-
const connect = input.value(connectOption);
|
|
26
|
-
const sessionId = input.value(sessionIdOption);
|
|
27
|
-
const shouldContinue = input.value(continueOption) === true || input.value(continueShortOption) === true;
|
|
28
|
-
const shouldResume = input.value(resumeOption) === true || input.value(resumeShortOption) === true;
|
|
29
|
-
const provider = input.value(providerOption);
|
|
30
|
-
const model = input.value(modelOption);
|
|
31
|
-
const pluginPackages = input.values(pluginPackageOption);
|
|
32
|
-
const promptArgs = input.remainingArgs[0] === "--" ? input.remainingArgs.slice(1) : input.remainingArgs;
|
|
33
|
-
const prompt = promptArgs.length === 1 &&
|
|
34
|
-
(input.remainingArgs[0] === "--" || !promptArgs[0].startsWith("-")) &&
|
|
35
|
-
promptArgs[0].length > 0
|
|
36
|
-
? promptArgs[0]
|
|
37
|
-
: undefined;
|
|
38
|
-
const modelErrors = provider !== undefined && model === undefined ? ["--provider requires --model"] : [];
|
|
39
|
-
const sessionSelectionErrors = [sessionId !== undefined, shouldContinue, shouldResume].filter(Boolean).length > 1
|
|
40
|
-
? ["--session-id, --continue, and --resume are mutually exclusive"]
|
|
41
|
-
: [];
|
|
42
|
-
const unsupportedErrors = input.remainingArgs.length === 0 || prompt !== undefined ? [] : unsupportedOptions("client", input);
|
|
43
|
-
const errors = [...authErrors, ...modelErrors, ...sessionSelectionErrors, ...unsupportedErrors];
|
|
44
|
-
if (errors.length > 0)
|
|
45
|
-
return { ok: false, errors };
|
|
46
|
-
return {
|
|
47
|
-
ok: true,
|
|
48
|
-
command: {
|
|
49
|
-
command: "client",
|
|
50
|
-
...(auth === undefined ? {} : { auth }),
|
|
51
|
-
...(connect === undefined ? {} : { connect }),
|
|
52
|
-
...(sessionId === undefined ? {} : { sessionId }),
|
|
53
|
-
...(shouldContinue ? { continue: true } : {}),
|
|
54
|
-
...(shouldResume ? { resume: true } : {}),
|
|
55
|
-
...(provider === undefined ? {} : { provider }),
|
|
56
|
-
...(model === undefined ? {} : { model }),
|
|
57
|
-
...(pluginPackages.length === 0 ? {} : { pluginPackages }),
|
|
58
|
-
...(prompt === undefined ? {} : { prompt }),
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
})
|
|
62
|
-
.action((command, context) => context.runClient(command));
|
|
63
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../src/cli/experimental/commands/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAEN,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,SAAS,EAET,kBAAkB,GAClB,MAAM,uBAAuB,CAAC;AAmB/B,MAAM,eAAe,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;AACrD,MAAM,cAAc,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;AAChD,MAAM,mBAAmB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;AAC7C,MAAM,YAAY,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;AAC5C,MAAM,iBAAiB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;AAC3C,MAAM,cAAc,GAAG,YAAY,CAAC,YAAY,CAAC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","sourcesContent":["import { Command, flagOption, stringOption } from \"../command.ts\";\nimport {\n\ttype AuthInput,\n\tauthTokenFileOption,\n\tauthTokenOption,\n\tconnectOption,\n\tparseAuth,\n\ttype TransportAddress,\n\tunsupportedOptions,\n} from \"../command-options.ts\";\n\nexport interface ClientCommand {\n\treadonly command: \"client\";\n\treadonly auth?: AuthInput;\n\treadonly connect?: TransportAddress;\n\treadonly sessionId?: string;\n\treadonly continue?: boolean;\n\treadonly resume?: boolean;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly pluginPackages?: readonly string[];\n\treadonly prompt?: string;\n}\n\nexport interface ClientCommandContext {\n\trunClient(command: ClientCommand): void | Promise<void>;\n}\n\nconst sessionIdOption = stringOption(\"--session-id\");\nconst continueOption = flagOption(\"--continue\");\nconst continueShortOption = flagOption(\"-c\");\nconst resumeOption = flagOption(\"--resume\");\nconst resumeShortOption = flagOption(\"-r\");\nconst providerOption = stringOption(\"--provider\");\nconst modelOption = stringOption(\"--model\");\nconst pluginPackageOption = stringOption(\"-e\", { repeatable: true });\n\nexport const clientCommand = new Command<ClientCommand, ClientCommandContext>(\"client\")\n\t.option(connectOption)\n\t.option(sessionIdOption)\n\t.option(continueOption)\n\t.option(continueShortOption)\n\t.option(resumeOption)\n\t.option(resumeShortOption)\n\t.option(providerOption)\n\t.option(modelOption)\n\t.option(pluginPackageOption)\n\t.option(authTokenOption)\n\t.option(authTokenFileOption)\n\t.build((input) => {\n\t\tconst { auth, errors: authErrors } = parseAuth(input);\n\t\tconst connect = input.value(connectOption);\n\t\tconst sessionId = input.value(sessionIdOption);\n\t\tconst shouldContinue = input.value(continueOption) === true || input.value(continueShortOption) === true;\n\t\tconst shouldResume = input.value(resumeOption) === true || input.value(resumeShortOption) === true;\n\t\tconst provider = input.value(providerOption);\n\t\tconst model = input.value(modelOption);\n\t\tconst pluginPackages = input.values(pluginPackageOption);\n\t\tconst promptArgs = input.remainingArgs[0] === \"--\" ? input.remainingArgs.slice(1) : input.remainingArgs;\n\t\tconst prompt =\n\t\t\tpromptArgs.length === 1 &&\n\t\t\t(input.remainingArgs[0] === \"--\" || !promptArgs[0]!.startsWith(\"-\")) &&\n\t\t\tpromptArgs[0]!.length > 0\n\t\t\t\t? promptArgs[0]\n\t\t\t\t: undefined;\n\t\tconst modelErrors = provider !== undefined && model === undefined ? [\"--provider requires --model\"] : [];\n\t\tconst sessionSelectionErrors =\n\t\t\t[sessionId !== undefined, shouldContinue, shouldResume].filter(Boolean).length > 1\n\t\t\t\t? [\"--session-id, --continue, and --resume are mutually exclusive\"]\n\t\t\t\t: [];\n\t\tconst unsupportedErrors =\n\t\t\tinput.remainingArgs.length === 0 || prompt !== undefined ? [] : unsupportedOptions(\"client\", input);\n\t\tconst errors = [...authErrors, ...modelErrors, ...sessionSelectionErrors, ...unsupportedErrors];\n\t\tif (errors.length > 0) return { ok: false, errors };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tcommand: {\n\t\t\t\tcommand: \"client\",\n\t\t\t\t...(auth === undefined ? {} : { auth }),\n\t\t\t\t...(connect === undefined ? {} : { connect }),\n\t\t\t\t...(sessionId === undefined ? {} : { sessionId }),\n\t\t\t\t...(shouldContinue ? { continue: true } : {}),\n\t\t\t\t...(shouldResume ? { resume: true } : {}),\n\t\t\t\t...(provider === undefined ? {} : { provider }),\n\t\t\t\t...(model === undefined ? {} : { model }),\n\t\t\t\t...(pluginPackages.length === 0 ? {} : { pluginPackages }),\n\t\t\t\t...(prompt === undefined ? {} : { prompt }),\n\t\t\t},\n\t\t};\n\t})\n\t.action((command, context) => context.runClient(command));\n"]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type ServerId } from "@earendil-works/pi-protocol";
|
|
2
|
-
import { Command } from "../command.ts";
|
|
3
|
-
import { type AuthInput } from "../command-options.ts";
|
|
4
|
-
export interface ServerCommand {
|
|
5
|
-
readonly command: "server";
|
|
6
|
-
readonly auth?: AuthInput;
|
|
7
|
-
readonly provider?: string;
|
|
8
|
-
readonly model?: string;
|
|
9
|
-
readonly pluginPackages?: readonly string[];
|
|
10
|
-
readonly serverId?: ServerId;
|
|
11
|
-
readonly sessionDir?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface ServerCommandContext {
|
|
14
|
-
runServer(command: ServerCommand): void | Promise<void>;
|
|
15
|
-
}
|
|
16
|
-
export declare const serverCommand: Command<ServerCommand, ServerCommandContext, ServerCommand>;
|
|
17
|
-
//# sourceMappingURL=server.d.ts.map
|