@skydiveai/pi-extensions 0.1.0-beta.2550 → 0.1.0-beta.2558

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.
Files changed (2) hide show
  1. package/dist/index.mjs +63 -4
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -4362,27 +4362,86 @@ function createSubagentExtension({ channelContext }) {
4362
4362
  }
4363
4363
  //#endregion
4364
4364
  //#region src/extensions/proactive-result.ts
4365
+ const proactiveShadowTool = {
4366
+ name: "get_latest_proactive_shadow_result",
4367
+ label: "Review proactive shadow result",
4368
+ description: "Use when your creator or an organization owner/admin asks what you most recently considered doing proactively or why. Returns the latest completed scheduled shadow evaluation, which is hypothetical and was not delivered. Explain the stored result faithfully without claiming that its proposed action or message was performed or sent.",
4369
+ parameters: Type.Object({}, { additionalProperties: false })
4370
+ };
4365
4371
  const contextSchema = z.object({
4366
- proactiveAction: z.literal(true),
4372
+ proactiveAction: z.literal(true).optional(),
4367
4373
  runId: z.string().uuid(),
4368
4374
  messageId: z.string().uuid()
4369
4375
  });
4370
4376
  function createProactiveResultExtension({ channelContext }) {
4371
4377
  return (pi) => {
4372
- if (!channelContext) return;
4373
4378
  let context;
4374
4379
  try {
4375
- context = contextSchema.safeParse(JSON.parse(channelContext));
4380
+ context = contextSchema.safeParse(JSON.parse(channelContext ?? ""));
4376
4381
  } catch (_error) {
4377
4382
  return;
4378
4383
  }
4379
4384
  if (!context.success) return;
4380
- const { runId, messageId } = context.data;
4385
+ const { proactiveAction, runId, messageId } = context.data;
4381
4386
  let registered = false;
4382
4387
  pi.on("session_start", async () => {
4383
4388
  if (registered) return;
4384
4389
  const client = sandboxClient();
4385
4390
  if (!client) return;
4391
+ if (!proactiveAction) {
4392
+ pi.registerTool({
4393
+ ...proactiveShadowTool,
4394
+ async execute(_toolCallId, _params, signal) {
4395
+ try {
4396
+ const response = await client["proactive-result"]["latest-shadow"].$get({ query: {
4397
+ runId,
4398
+ messageId
4399
+ } }, { init: { signal } });
4400
+ if (response.status === 404) return {
4401
+ content: [{
4402
+ type: "text",
4403
+ text: "Proactive shadow result review is not available yet."
4404
+ }],
4405
+ isError: false,
4406
+ details: {}
4407
+ };
4408
+ if (!response.ok) throw new Error(`proactive shadow result lookup failed: ${response.status}`);
4409
+ const { result } = await response.json();
4410
+ if (!result) return {
4411
+ content: [{
4412
+ type: "text",
4413
+ text: "No completed scheduled shadow result is available to this conversation."
4414
+ }],
4415
+ isError: false,
4416
+ details: {}
4417
+ };
4418
+ return {
4419
+ content: [{
4420
+ type: "text",
4421
+ text: JSON.stringify({
4422
+ result,
4423
+ reminder: "This was a shadow evaluation. Nothing in it was performed or delivered."
4424
+ })
4425
+ }],
4426
+ isError: false,
4427
+ details: {}
4428
+ };
4429
+ } catch (err) {
4430
+ logger.warn({ err }, "proactive shadow result lookup failed");
4431
+ return {
4432
+ content: [{
4433
+ type: "text",
4434
+ text: "The proactive shadow result could not be retrieved."
4435
+ }],
4436
+ isError: true,
4437
+ details: {}
4438
+ };
4439
+ }
4440
+ }
4441
+ });
4442
+ registered = true;
4443
+ return;
4444
+ }
4386
4445
  try {
4387
4446
  const response = await client["proactive-result"].$get({ query: {
4388
4447
  runId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skydiveai/pi-extensions",
3
- "version": "0.1.0-beta.2550",
3
+ "version": "0.1.0-beta.2558",
4
4
  "homepage": "https://skydive.com",
5
5
  "license": "MIT",
6
6
  "author": "Create, Inc.",