@theokit/sdk 4.7.1 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/agent.d.ts CHANGED
@@ -166,6 +166,14 @@ export declare class Agent {
166
166
  * @public
167
167
  */
168
168
  static unarchive(agentId: string, _options?: AgentOperationOptions): Promise<void>;
169
+ /**
170
+ * Set the human-facing `name` of a registered agent (the label `Agent.list()` returns). The registry
171
+ * already carries a `name` field; this is the missing public mutator for it. Runtime-agnostic (mutates
172
+ * the local per-cwd registry for local agents; the cloud registry for cloud agents).
173
+ *
174
+ * @public
175
+ */
176
+ static rename(agentId: string, name: string, _options?: AgentOperationOptions): Promise<void>;
169
177
  /**
170
178
  * Permanently delete a cloud agent.
171
179
  *
package/dist/cron.cjs CHANGED
@@ -12953,6 +12953,192 @@ function assistantMessage(message) {
12953
12953
  return result;
12954
12954
  }
12955
12955
 
12956
+ // src/internal/llm/responses.ts
12957
+ function messageToInputItems(message) {
12958
+ const items = [];
12959
+ if (message.role === "user") {
12960
+ const content = [];
12961
+ for (const part of message.content) {
12962
+ if (part.type === "text") {
12963
+ content.push({ type: "input_text", text: part.text });
12964
+ } else if (part.type === "image") {
12965
+ const url = part.source.type === "base64" ? `data:${part.source.media_type};base64,${part.source.data}` : part.source.url;
12966
+ content.push({ type: "input_image", image_url: url });
12967
+ } else if (part.type === "tool_result") {
12968
+ items.push({
12969
+ type: "function_call_output",
12970
+ call_id: part.toolUseId,
12971
+ output: toStringToolResultContent(part.content, "openai-responses")
12972
+ });
12973
+ }
12974
+ }
12975
+ if (content.length > 0) items.push({ role: "user", content });
12976
+ return items;
12977
+ }
12978
+ if (message.role === "assistant") {
12979
+ const content = [];
12980
+ for (const part of message.content) {
12981
+ if (part.type === "text") {
12982
+ content.push({ type: "output_text", text: part.text });
12983
+ } else if (part.type === "tool_use") {
12984
+ items.push({
12985
+ type: "function_call",
12986
+ call_id: part.id,
12987
+ name: part.name,
12988
+ arguments: JSON.stringify(part.input)
12989
+ });
12990
+ }
12991
+ }
12992
+ if (content.length > 0) items.push({ role: "assistant", content });
12993
+ return items;
12994
+ }
12995
+ const text = message.content.filter((p) => p.type === "text").map((p) => p.text).join("\n");
12996
+ if (text.length > 0) items.push({ role: "system", content: text });
12997
+ return items;
12998
+ }
12999
+ function buildResponsesBody(request) {
13000
+ const input = [];
13001
+ for (const message of request.messages) {
13002
+ for (const item of messageToInputItems(message)) input.push(item);
13003
+ }
13004
+ const body = { model: request.model, input, stream: true, store: false };
13005
+ const instructions = collapseSystemText(request.system);
13006
+ if (instructions.length > 0) body.instructions = instructions;
13007
+ if (request.maxTokens !== void 0) body.max_output_tokens = request.maxTokens;
13008
+ if (request.temperature !== void 0) body.temperature = request.temperature;
13009
+ const tools = (request.tools ?? []).map((tool) => ({
13010
+ type: "function",
13011
+ name: tool.name,
13012
+ description: tool.description,
13013
+ parameters: tool.inputSchema,
13014
+ strict: false
13015
+ }));
13016
+ if (tools.length > 0) body.tools = tools;
13017
+ if (request.reasoning !== void 0) body.reasoning = { effort: request.reasoning.effort };
13018
+ return body;
13019
+ }
13020
+ var ResponsesApiClient = class {
13021
+ constructor(options) {
13022
+ this.options = options;
13023
+ this.name = options.providerName ?? "openai-responses";
13024
+ this.baseUrl = (options.baseUrl ?? "https://api.openai.com/v1").replace(/\/+$/, "");
13025
+ this.fetchImpl = options.fetch ?? fetch;
13026
+ }
13027
+ options;
13028
+ name;
13029
+ baseUrl;
13030
+ fetchImpl;
13031
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: the SSE dispatch (text / reasoning / tool-call add+delta+done / terminal+usage / error) is one cohesive state machine, mirroring OpenAIStreamAccumulator.consume.
13032
+ async *stream(request, signal) {
13033
+ const providerId = this.options.providerName ?? "openai";
13034
+ const headers = {
13035
+ "content-type": "application/json",
13036
+ accept: "text/event-stream",
13037
+ authorization: `Bearer ${this.options.apiKey}`,
13038
+ ...this.options.extraHeaders ?? {}
13039
+ };
13040
+ const url = `${this.baseUrl}/responses`;
13041
+ const response = await this.fetchImpl(url, {
13042
+ method: "POST",
13043
+ signal,
13044
+ headers,
13045
+ body: JSON.stringify(buildResponsesBody(request))
13046
+ });
13047
+ if (!response.ok) {
13048
+ const text2 = await response.text().catch(() => "");
13049
+ let body = text2;
13050
+ try {
13051
+ body = JSON.parse(text2);
13052
+ } catch {
13053
+ }
13054
+ throw mapOpenAICompatibleError({
13055
+ providerId,
13056
+ status: response.status,
13057
+ body,
13058
+ headers: response.headers,
13059
+ endpoint: "/responses"
13060
+ });
13061
+ }
13062
+ let text = "";
13063
+ const toolCalls = [];
13064
+ let stopReason = "end_turn";
13065
+ let inputTokens;
13066
+ let outputTokens;
13067
+ let reasoningTokens;
13068
+ const pending = {};
13069
+ if (response.body !== null) {
13070
+ for await (const record of parseSseStream(response.body, signal)) {
13071
+ if (record.data === "[DONE]") break;
13072
+ let event;
13073
+ try {
13074
+ event = JSON.parse(record.data);
13075
+ } catch {
13076
+ continue;
13077
+ }
13078
+ const t = event.type;
13079
+ if (t === "response.output_text.delta") {
13080
+ const d = event.delta ?? "";
13081
+ if (d.length > 0) {
13082
+ text += d;
13083
+ yield { type: "text_delta", text: d };
13084
+ }
13085
+ } else if (t === "response.reasoning_summary_text.delta" || t === "response.reasoning_text.delta") {
13086
+ const d = event.delta ?? "";
13087
+ if (d.length > 0) yield { type: "reasoning_delta", text: d };
13088
+ } else if (t === "response.output_item.added" && event.item?.type === "function_call") {
13089
+ const id = event.item.id ?? event.item.call_id ?? "call-0";
13090
+ pending[id] = {
13091
+ callId: event.item.call_id ?? id,
13092
+ name: event.item.name ?? "",
13093
+ args: event.item.arguments ?? ""
13094
+ };
13095
+ } else if (t === "response.function_call_arguments.delta") {
13096
+ const c = event.item_id !== void 0 ? pending[event.item_id] : void 0;
13097
+ if (c !== void 0) c.args += event.delta ?? "";
13098
+ } else if (t === "response.output_item.done" && event.item?.type === "function_call") {
13099
+ const id = event.item.id ?? event.item.call_id ?? "call-0";
13100
+ const c = pending[id] ?? {
13101
+ callId: event.item.call_id ?? id,
13102
+ name: event.item.name ?? "",
13103
+ args: event.item.arguments ?? ""
13104
+ };
13105
+ const rawArgs = event.item.arguments ?? c.args;
13106
+ const call = {
13107
+ type: "tool_use",
13108
+ id: c.callId,
13109
+ name: c.name.length > 0 ? c.name : event.item.name ?? "",
13110
+ input: parseToolArguments(rawArgs)
13111
+ };
13112
+ toolCalls.push(call);
13113
+ delete pending[id];
13114
+ yield { type: "tool_use", id: call.id, name: call.name, input: call.input };
13115
+ } else if (t === "response.completed" || t === "response.incomplete") {
13116
+ const usage = event.response?.usage;
13117
+ if (usage !== void 0) {
13118
+ inputTokens = usage.input_tokens;
13119
+ outputTokens = usage.output_tokens;
13120
+ reasoningTokens = usage.output_tokens_details?.reasoning_tokens;
13121
+ }
13122
+ stopReason = t === "response.incomplete" ? "max_tokens" : "end_turn";
13123
+ } else if (t === "response.failed" || t === "error") {
13124
+ const msg = event.response?.error?.message ?? event.message ?? "responses stream failed";
13125
+ yield { type: "error", message: msg };
13126
+ throw mapOpenAICompatibleError({
13127
+ providerId,
13128
+ status: 502,
13129
+ body: { error: { message: msg } },
13130
+ headers: response.headers,
13131
+ endpoint: "/responses"
13132
+ });
13133
+ }
13134
+ }
13135
+ }
13136
+ if (toolCalls.length > 0 && stopReason === "end_turn") stopReason = "tool_use";
13137
+ yield { type: "stop", reason: stopReason };
13138
+ return makeLlmFinish({ stopReason, text, toolCalls, inputTokens, outputTokens, reasoningTokens });
13139
+ }
13140
+ };
13141
+
12956
13142
  // src/internal/llm/pool-aware-client.ts
12957
13143
  init_errors();
12958
13144
 
@@ -13521,6 +13707,14 @@ function selectTransport(profile, apiKey) {
13521
13707
  const realKey = apiKey === "__bedrock_lazy_token__" ? void 0 : apiKey;
13522
13708
  return new BedrockAnthropicClient(realKey !== void 0 ? { apiKey: realKey } : {});
13523
13709
  }
13710
+ if (profile.apiMode === "responses_api") {
13711
+ return new ResponsesApiClient({
13712
+ apiKey,
13713
+ ...profile.baseUrl !== void 0 ? { baseUrl: profile.baseUrl } : {},
13714
+ ...profile.extraHeaders !== void 0 ? { extraHeaders: profile.extraHeaders } : {},
13715
+ providerName: profile.name
13716
+ });
13717
+ }
13524
13718
  throw new ConfigurationError(
13525
13719
  `Provider "${profile.name}" requires apiMode "${profile.apiMode}" but no transport is registered. Install a third-party transport plugin (@theokit-transport-${profile.apiMode}) or use a provider with apiMode "chat_completions" or "anthropic_messages".`,
13526
13720
  { code: "transport_unavailable" }
@@ -17810,6 +18004,11 @@ async function setArchivedFlag(agentId, archived) {
17810
18004
  updateRegisteredAgent(agentId, { archived });
17811
18005
  await flushRegistrySaves();
17812
18006
  }
18007
+ async function setAgentName(agentId, name) {
18008
+ await getRegisteredAgentOrThrow(agentId);
18009
+ updateRegisteredAgent(agentId, { name });
18010
+ await flushRegistrySaves();
18011
+ }
17813
18012
  async function getRegisteredAgentOrThrow(agentId) {
17814
18013
  let agent = getRegisteredAgent(agentId);
17815
18014
  if (agent === void 0) {
@@ -18089,6 +18288,16 @@ var Agent = class _Agent {
18089
18288
  static unarchive(agentId, _options = {}) {
18090
18289
  return setArchivedFlag(agentId, false);
18091
18290
  }
18291
+ /**
18292
+ * Set the human-facing `name` of a registered agent (the label `Agent.list()` returns). The registry
18293
+ * already carries a `name` field; this is the missing public mutator for it. Runtime-agnostic (mutates
18294
+ * the local per-cwd registry for local agents; the cloud registry for cloud agents).
18295
+ *
18296
+ * @public
18297
+ */
18298
+ static async rename(agentId, name, _options = {}) {
18299
+ await setAgentName(agentId, name);
18300
+ }
18092
18301
  /**
18093
18302
  * Permanently delete a cloud agent.
18094
18303
  *