@ui-calling/adk 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 +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Who, SurfaceLink, UiCalling } from '@ui-calling/core';
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Pass as `stateDelta` on a turn a screen event started: `runner.runAsync({ userId, sessionId, newMessage, stateDelta: WOKEN_TURN })`.
|
|
6
|
-
*
|
|
6
|
+
* `stay_silent` is listed on every turn and only works on these. A `temp:` key lasts only that turn.
|
|
7
7
|
*/
|
|
8
8
|
declare const WOKEN_TURN: {
|
|
9
9
|
readonly "temp:ui_calling_woken": true;
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ function adkToolset(ui, opts = {}) {
|
|
|
5
5
|
return new UiCallingToolset(ui, opts);
|
|
6
6
|
}
|
|
7
7
|
var defaultWho = (ctx) => ({ conversationId: ctx.sessionId, subject: ctx.userId });
|
|
8
|
+
var isWoken = (ctx) => ctx?.state.get(Object.keys(WOKEN_TURN)[0]) === true;
|
|
8
9
|
var UiCallingToolset = class extends BaseToolset {
|
|
9
10
|
constructor(ui, opts) {
|
|
10
11
|
super();
|
|
@@ -13,11 +14,11 @@ var UiCallingToolset = class extends BaseToolset {
|
|
|
13
14
|
}
|
|
14
15
|
ui;
|
|
15
16
|
opts;
|
|
16
|
-
// Asked on every model call, so the list
|
|
17
|
+
// Asked on every model call. stay_silent is always listed, so the list doesn't change between turns (models with
|
|
18
|
+
// preserved thinking reject earlier reasoning when it does); a user's turn refuses it when it's called.
|
|
17
19
|
async getTools(ctx) {
|
|
18
|
-
const woken = ctx?.state.get(Object.keys(WOKEN_TURN)[0]) === true;
|
|
19
20
|
const filter = ctx && this.opts.filter ? (name) => this.opts.filter(name, ctx) : void 0;
|
|
20
|
-
return this.ui.tools({ woken, filter }).map((spec) => new SurfaceTool(this.ui, spec, this.opts, filter));
|
|
21
|
+
return this.ui.tools({ woken: isWoken(ctx), filter }).map((spec) => new SurfaceTool(this.ui, spec, this.opts, filter));
|
|
21
22
|
}
|
|
22
23
|
async close() {
|
|
23
24
|
}
|
|
@@ -39,7 +40,8 @@ var SurfaceTool = class extends BaseTool {
|
|
|
39
40
|
return { name: this.name, description: this.description, parametersJsonSchema: this.spec.input_schema };
|
|
40
41
|
}
|
|
41
42
|
async runAsync({ args, toolContext }) {
|
|
42
|
-
const
|
|
43
|
+
const who = { ...(this.opts.who ?? defaultWho)(toolContext), woken: isWoken(toolContext) };
|
|
44
|
+
const run = await this.ui.runTool(this.name, args, who, this.filter);
|
|
43
45
|
if (run.ok && run.silent) {
|
|
44
46
|
toolContext.actions.skipSummarization = true;
|
|
45
47
|
this.opts.onSilent?.(run.reason, toolContext);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { BaseTool, BaseToolset, type Context, type ReadonlyContext, type RunAsyncToolRequest } from \"@google/adk\";\nimport type { SurfaceLink, ToolSpec, UiCalling, Who } from \"@ui-calling/core\";\n\n/**\n * Pass as `stateDelta` on a turn a screen event started: `runner.runAsync({ userId, sessionId, newMessage, stateDelta: WOKEN_TURN })`.\n *
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { BaseTool, BaseToolset, type Context, type ReadonlyContext, type RunAsyncToolRequest } from \"@google/adk\";\nimport type { SurfaceLink, ToolSpec, UiCalling, Who } from \"@ui-calling/core\";\n\n/**\n * Pass as `stateDelta` on a turn a screen event started: `runner.runAsync({ userId, sessionId, newMessage, stateDelta: WOKEN_TURN })`.\n * `stay_silent` is listed on every turn and only works on these. A `temp:` key lasts only that turn.\n */\nexport const WOKEN_TURN = { \"temp:ui_calling_woken\": true } as const;\n\nexport type AdkAdapterOptions = {\n /**\n * Who the tools run for. Defaults to ADK's own session: `{ conversationId: ctx.sessionId, subject: ctx.userId }`,\n * so an event's `conversationId` and `subject` are the `sessionId` and `userId` to run the woken turn with.\n */\n who?: (ctx: ReadonlyContext) => Who;\n /** Offer only some surfaces, e.g. hide everything but an account-linking screen until the user is known. */\n filter?: (toolName: string, ctx: ReadonlyContext) => boolean;\n /** Called with every link a tool call creates: deliver it on your channel (e.g. as a WhatsApp button). */\n onLink?: (link: SurfaceLink, ctx: Context) => void;\n /** Called when the model calls `stay_silent`. The turn ends there: send nothing for it, whatever text came before. */\n onSilent?: (reason: string, ctx: Context) => void;\n};\n\n/**\n * Surfaces as an ADK toolset. One agent serves every user: the tools read who they run for from the session.\n *\n * const agent = new LlmAgent({ name: \"shop\", model: \"gemini-3.5-flash-lite\", instruction,\n * tools: [adkToolset(ui, { onLink: (link, ctx) => links.get(ctx.sessionId)?.push(link) })] });\n */\nexport function adkToolset(ui: UiCalling, opts: AdkAdapterOptions = {}): BaseToolset {\n return new UiCallingToolset(ui, opts);\n}\n\nconst defaultWho = (ctx: ReadonlyContext): Who => ({ conversationId: ctx.sessionId, subject: ctx.userId });\nconst isWoken = (ctx?: ReadonlyContext) => ctx?.state.get(Object.keys(WOKEN_TURN)[0]!) === true;\n\nclass UiCallingToolset extends BaseToolset {\n constructor(\n private ui: UiCalling,\n private opts: AdkAdapterOptions,\n ) {\n super();\n }\n\n // Asked on every model call. stay_silent is always listed, so the list doesn't change between turns (models with\n // preserved thinking reject earlier reasoning when it does); a user's turn refuses it when it's called.\n async getTools(ctx?: ReadonlyContext): Promise<BaseTool[]> {\n const filter = ctx && this.opts.filter ? (name: string) => this.opts.filter!(name, ctx) : undefined;\n return this.ui.tools({ woken: isWoken(ctx), filter }).map((spec) => new SurfaceTool(this.ui, spec, this.opts, filter));\n }\n\n async close() {}\n}\n\nclass SurfaceTool extends BaseTool {\n constructor(\n private ui: UiCalling,\n private spec: ToolSpec,\n private opts: AdkAdapterOptions,\n private filter?: (toolName: string) => boolean,\n ) {\n super({ name: spec.name, description: spec.description });\n }\n\n // `parametersJsonSchema` takes JSON Schema as is; `parameters` is Gemini's narrower OpenAPI subset.\n override _getDeclaration() {\n return { name: this.name, description: this.description, parametersJsonSchema: this.spec.input_schema };\n }\n\n async runAsync({ args, toolContext }: RunAsyncToolRequest) {\n const who = { ...(this.opts.who ?? defaultWho)(toolContext), woken: isWoken(toolContext) };\n const run = await this.ui.runTool(this.name, args, who, this.filter);\n if (run.ok && run.silent) {\n // End the turn here: no extra model call to hear it say nothing.\n toolContext.actions.skipSummarization = true;\n this.opts.onSilent?.(run.reason, toolContext);\n } else if (run.ok) this.opts.onLink?.(run.link, toolContext);\n // The model reads this object as the tool output; failures say why instead of throwing.\n return JSON.parse(run.content) as Record<string, unknown>;\n }\n}\n"],"mappings":";AAAA,SAAS,UAAU,mBAAiF;AAO7F,IAAM,aAAa,EAAE,yBAAyB,KAAK;AAsBnD,SAAS,WAAW,IAAe,OAA0B,CAAC,GAAgB;AACnF,SAAO,IAAI,iBAAiB,IAAI,IAAI;AACtC;AAEA,IAAM,aAAa,CAAC,SAA+B,EAAE,gBAAgB,IAAI,WAAW,SAAS,IAAI,OAAO;AACxG,IAAM,UAAU,CAAC,QAA0B,KAAK,MAAM,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC,CAAE,MAAM;AAE3F,IAAM,mBAAN,cAA+B,YAAY;AAAA,EACzC,YACU,IACA,MACR;AACA,UAAM;AAHE;AACA;AAAA,EAGV;AAAA,EAJU;AAAA,EACA;AAAA;AAAA;AAAA,EAOV,MAAM,SAAS,KAA4C;AACzD,UAAM,SAAS,OAAO,KAAK,KAAK,SAAS,CAAC,SAAiB,KAAK,KAAK,OAAQ,MAAM,GAAG,IAAI;AAC1F,WAAO,KAAK,GAAG,MAAM,EAAE,OAAO,QAAQ,GAAG,GAAG,OAAO,CAAC,EAAE,IAAI,CAAC,SAAS,IAAI,YAAY,KAAK,IAAI,MAAM,KAAK,MAAM,MAAM,CAAC;AAAA,EACvH;AAAA,EAEA,MAAM,QAAQ;AAAA,EAAC;AACjB;AAEA,IAAM,cAAN,cAA0B,SAAS;AAAA,EACjC,YACU,IACA,MACA,MACA,QACR;AACA,UAAM,EAAE,MAAM,KAAK,MAAM,aAAa,KAAK,YAAY,CAAC;AALhD;AACA;AACA;AACA;AAAA,EAGV;AAAA,EANU;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAMD,kBAAkB;AACzB,WAAO,EAAE,MAAM,KAAK,MAAM,aAAa,KAAK,aAAa,sBAAsB,KAAK,KAAK,aAAa;AAAA,EACxG;AAAA,EAEA,MAAM,SAAS,EAAE,MAAM,YAAY,GAAwB;AACzD,UAAM,MAAM,EAAE,IAAI,KAAK,KAAK,OAAO,YAAY,WAAW,GAAG,OAAO,QAAQ,WAAW,EAAE;AACzF,UAAM,MAAM,MAAM,KAAK,GAAG,QAAQ,KAAK,MAAM,MAAM,KAAK,KAAK,MAAM;AACnE,QAAI,IAAI,MAAM,IAAI,QAAQ;AAExB,kBAAY,QAAQ,oBAAoB;AACxC,WAAK,KAAK,WAAW,IAAI,QAAQ,WAAW;AAAA,IAC9C,WAAW,IAAI,GAAI,MAAK,KAAK,SAAS,IAAI,MAAM,WAAW;AAE3D,WAAO,KAAK,MAAM,IAAI,OAAO;AAAA,EAC/B;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ui-calling/adk",
|
|
3
|
-
"version": "0.1.0-preview.
|
|
3
|
+
"version": "0.1.0-preview.3",
|
|
4
4
|
"description": "Use ui-calling surfaces as tools with Google's Agent Development Kit (ADK) for TypeScript.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"removeNodeProtocol": false
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@ui-calling/core": "^0.1.0-preview.
|
|
53
|
+
"@ui-calling/core": "^0.1.0-preview.3"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@google/adk": ">=2.5.0"
|