@ui-calling/openai 0.1.0-preview.1 → 0.1.0-preview.3

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/index.d.ts CHANGED
@@ -1,7 +1,11 @@
1
1
  import { UiCalling, Who, ToolRun } from '@ui-calling/core';
2
2
 
3
3
  type Filter = (toolName: string) => boolean;
4
- /** `woken`: a screen event started this turn, not a user message, so `stay_silent` is offered too. The run then has `run.silent`. */
4
+ /**
5
+ * `woken`: set on every turn if your agent runs on screen events (`true` when a screen started it, `false` when the
6
+ * user wrote). `stay_silent` is then always offered, so the tool list never changes; pass the same turn in `who`
7
+ * (`{ ...who, woken }`) to the run helpers, which refuse it on the user's turns and return `run.silent` on woken ones.
8
+ */
5
9
  type Turn = {
6
10
  woken?: boolean;
7
11
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { ToolRun, UiCalling, Who } from \"@ui-calling/core\";\n\ntype Filter = (toolName: string) => boolean;\n/** `woken`: a screen event started this turn, not a user message, so `stay_silent` is offered too. The run then has `run.silent`. */\ntype Turn = { woken?: boolean };\n\n/** Function tools for the Responses API: `client.responses.create({ tools })`. */\nexport function openaiResponsesTools(ui: UiCalling, filter?: Filter, turn: Turn = {}) {\n return ui\n .tools({ ...turn, filter })\n .map((t) => ({ type: \"function\" as const, name: t.name, description: t.description, parameters: t.input_schema, strict: false }));\n}\n\n/** Function tools for Chat Completions: `client.chat.completions.create({ tools })`. */\nexport function openaiChatTools(ui: UiCalling, filter?: Filter, turn: Turn = {}) {\n return ui\n .tools({ ...turn, filter })\n .map((t) => ({\n type: \"function\" as const,\n function: { name: t.name, description: t.description, parameters: t.input_schema },\n }));\n}\n\n/**\n * Run a Responses API `function_call` output item. Returns the `function_call_output` item to add to\n * the next request's input, and the run: deliver `run.link` when `run.ok`, send nothing this turn when `run.silent`.\n */\nexport async function runResponsesFunctionCall(\n ui: UiCalling,\n call: { call_id: string; name: string; arguments: string },\n who: Who,\n /** The filter you gave `openaiResponsesTools`: a tool the model wasn't offered is refused. */\n filter?: Filter,\n): Promise<{ item: { type: \"function_call_output\"; call_id: string; output: string }; run: ToolRun }> {\n const run = await runWithArguments(ui, call.name, call.arguments, who, filter);\n return { item: { type: \"function_call_output\", call_id: call.call_id, output: run.content }, run };\n}\n\n/** Run a Chat Completions tool call. Returns the `tool` message to append, and the run. */\nexport async function runChatToolCall(\n ui: UiCalling,\n call: { id: string; function: { name: string; arguments: string } },\n who: Who,\n /** The filter you gave `openaiChatTools`: a tool the model wasn't offered is refused. */\n filter?: Filter,\n): Promise<{ message: { role: \"tool\"; tool_call_id: string; content: string }; run: ToolRun }> {\n const run = await runWithArguments(ui, call.function.name, call.function.arguments, who, filter);\n return { message: { role: \"tool\", tool_call_id: call.id, content: run.content }, run };\n}\n\n// OpenAI sends arguments as a JSON string; malformed JSON becomes an error result the model can fix.\nasync function runWithArguments(ui: UiCalling, name: string, args: string, who: Who, filter?: Filter): Promise<ToolRun> {\n let input: unknown;\n try {\n input = JSON.parse(args || \"{}\");\n } catch {\n const error = { code: \"invalid_arguments\", message: \"Tool arguments were not valid JSON\" };\n return { ok: false, content: JSON.stringify({ status: \"error\", ...error }), error };\n }\n return ui.runTool(name, input, who, filter);\n}\n"],"mappings":";AAOO,SAAS,qBAAqB,IAAe,QAAiB,OAAa,CAAC,GAAG;AACpF,SAAO,GACJ,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,EACzB,IAAI,CAAC,OAAO,EAAE,MAAM,YAAqB,MAAM,EAAE,MAAM,aAAa,EAAE,aAAa,YAAY,EAAE,cAAc,QAAQ,MAAM,EAAE;AACpI;AAGO,SAAS,gBAAgB,IAAe,QAAiB,OAAa,CAAC,GAAG;AAC/E,SAAO,GACJ,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,EACzB,IAAI,CAAC,OAAO;AAAA,IACX,MAAM;AAAA,IACN,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,EAAE,aAAa,YAAY,EAAE,aAAa;AAAA,EACnF,EAAE;AACN;AAMA,eAAsB,yBACpB,IACA,MACA,KAEA,QACoG;AACpG,QAAM,MAAM,MAAM,iBAAiB,IAAI,KAAK,MAAM,KAAK,WAAW,KAAK,MAAM;AAC7E,SAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,SAAS,KAAK,SAAS,QAAQ,IAAI,QAAQ,GAAG,IAAI;AACnG;AAGA,eAAsB,gBACpB,IACA,MACA,KAEA,QAC6F;AAC7F,QAAM,MAAM,MAAM,iBAAiB,IAAI,KAAK,SAAS,MAAM,KAAK,SAAS,WAAW,KAAK,MAAM;AAC/F,SAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,cAAc,KAAK,IAAI,SAAS,IAAI,QAAQ,GAAG,IAAI;AACvF;AAGA,eAAe,iBAAiB,IAAe,MAAc,MAAc,KAAU,QAAmC;AACtH,MAAI;AACJ,MAAI;AACF,YAAQ,KAAK,MAAM,QAAQ,IAAI;AAAA,EACjC,QAAQ;AACN,UAAM,QAAQ,EAAE,MAAM,qBAAqB,SAAS,qCAAqC;AACzF,WAAO,EAAE,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE,QAAQ,SAAS,GAAG,MAAM,CAAC,GAAG,MAAM;AAAA,EACpF;AACA,SAAO,GAAG,QAAQ,MAAM,OAAO,KAAK,MAAM;AAC5C;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { ToolRun, UiCalling, Who } from \"@ui-calling/core\";\n\ntype Filter = (toolName: string) => boolean;\n/**\n * `woken`: set on every turn if your agent runs on screen events (`true` when a screen started it, `false` when the\n * user wrote). `stay_silent` is then always offered, so the tool list never changes; pass the same turn in `who`\n * (`{ ...who, woken }`) to the run helpers, which refuse it on the user's turns and return `run.silent` on woken ones.\n */\ntype Turn = { woken?: boolean };\n\n/** Function tools for the Responses API: `client.responses.create({ tools })`. */\nexport function openaiResponsesTools(ui: UiCalling, filter?: Filter, turn: Turn = {}) {\n return ui\n .tools({ ...turn, filter })\n .map((t) => ({ type: \"function\" as const, name: t.name, description: t.description, parameters: t.input_schema, strict: false }));\n}\n\n/** Function tools for Chat Completions: `client.chat.completions.create({ tools })`. */\nexport function openaiChatTools(ui: UiCalling, filter?: Filter, turn: Turn = {}) {\n return ui\n .tools({ ...turn, filter })\n .map((t) => ({\n type: \"function\" as const,\n function: { name: t.name, description: t.description, parameters: t.input_schema },\n }));\n}\n\n/**\n * Run a Responses API `function_call` output item. Returns the `function_call_output` item to add to\n * the next request's input, and the run: deliver `run.link` when `run.ok`, send nothing this turn when `run.silent`.\n */\nexport async function runResponsesFunctionCall(\n ui: UiCalling,\n call: { call_id: string; name: string; arguments: string },\n who: Who,\n /** The filter you gave `openaiResponsesTools`: a tool the model wasn't offered is refused. */\n filter?: Filter,\n): Promise<{ item: { type: \"function_call_output\"; call_id: string; output: string }; run: ToolRun }> {\n const run = await runWithArguments(ui, call.name, call.arguments, who, filter);\n return { item: { type: \"function_call_output\", call_id: call.call_id, output: run.content }, run };\n}\n\n/** Run a Chat Completions tool call. Returns the `tool` message to append, and the run. */\nexport async function runChatToolCall(\n ui: UiCalling,\n call: { id: string; function: { name: string; arguments: string } },\n who: Who,\n /** The filter you gave `openaiChatTools`: a tool the model wasn't offered is refused. */\n filter?: Filter,\n): Promise<{ message: { role: \"tool\"; tool_call_id: string; content: string }; run: ToolRun }> {\n const run = await runWithArguments(ui, call.function.name, call.function.arguments, who, filter);\n return { message: { role: \"tool\", tool_call_id: call.id, content: run.content }, run };\n}\n\n// OpenAI sends arguments as a JSON string; malformed JSON becomes an error result the model can fix.\nasync function runWithArguments(ui: UiCalling, name: string, args: string, who: Who, filter?: Filter): Promise<ToolRun> {\n let input: unknown;\n try {\n input = JSON.parse(args || \"{}\");\n } catch {\n const error = { code: \"invalid_arguments\", message: \"Tool arguments were not valid JSON\" };\n return { ok: false, content: JSON.stringify({ status: \"error\", ...error }), error };\n }\n return ui.runT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MAAM;AAAA,EACpF;AACA,SAAO,GAAG,QAAQ,MAAM,OAAO,KAAK,MAAM;AAC5C;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui-calling/openai",
3
- "version": "0.1.0-preview.1",
3
+ "version": "0.1.0-preview.3",
4
4
  "description": "Use ui-calling surfaces as function tools with OpenAI's Responses or Chat Completions API. No SDK dependency.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -48,7 +48,7 @@
48
48
  "removeNodeProtocol": false
49
49
  },
50
50
  "dependencies": {
51
- "@ui-calling/core": "^0.1.0-preview.1"
51
+ "@ui-calling/core": "^0.1.0-preview.3"
52
52
  },
53
53
  "publishConfig": {
54
54
  "access": "public"